Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recursive xslt

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
Hello

I am working on a xslt program to process xml into html that has a list of requirements for a program.

Many of the requirements are just as simple as this:

Code:
<requirement>128Mb onboard video card memory</requirement>
<requirement>...</requirement>
<requirement>...</requirement>

However some of them have sub-requirements:

Code:
<requirement>Video card
   <requirement>128Mb onboard memory</requirement>
   <requirement>PCIxpress or AGP 8x</requirement>
   <requirement>Dual screen</requirement>
</requirement>
<requirement>...</requirement>
<requirement>
    <requirement>...</requirement>
    <requirement>...</requirement>
</requirement>

Is there a way to make my xsl:template match to make this look nice in something like a nested <ul> layout?

Thanks

Robert Carpenter
"Disobedience to conscience is voluntary; bad poetry, on the other hand, is usually not made on purpose." - C.S. Lewis (Preface to Paradise Lost)
ô¿ô
 
Given XML of:
Code:
<requirements>
  <requirement>Video card
   <requirement>128Mb onboard memory</requirement>
    <requirement>PCIxpress or AGP 8x</requirement>
    <requirement>Dual screen</requirement>
  </requirement>
  <requirement>...</requirement>
  <requirement>
    <requirement>...</requirement>
    <requirement>...</requirement>
  </requirement>
</requirements>
I would probably do something like:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="requirements">
    <html>
      <head>
        <title>Requirements</title>
      </head>
      <body>
        <ul>
          <xsl:apply-templates/>
        </ul>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="requirement">
    <li>
      <xsl:value-of select="text()"/>
      <xsl:if test="requirement">
        <ul>
          <xsl:apply-templates select="requirement"/>
        </ul>
      </xsl:if>
    </li>
  </xsl:template>
</xsl:stylesheet>

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top