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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show Tree Structure in XSL

Status
Not open for further replies.

jdbolt

Programmer
Aug 10, 2005
89
CA
Hi,

I came on this forum a few days to get a problem solved and I was helped really quickly so I'm hoping for a simialr experience this time! :)

I have an XML file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<root type='foo'>
<child>
<modifier>BBCDS</modifier>
<modifierdescription>BBCDS Project</modifierdescription>
<level>2</level>
</child>
<child>
<modifier>BFCI</modifier>
<modifierdescription>BFCI Project</modifierdescription>
<level>3</level>
</child>
<child>
<modifier>DMS</modifier>
<modifierdescription>Document Managment System</modifierdescription>
<level>4</level>
</child>
</root>



I was wanting to represent this as a tree structure - by the way to confuse matters, the order is backwards! (the highest number is the root parent. For example


- DMS

- BFCI

- BBCDS

Note: There number of parent portals is not limitied, although in practice it would only ever be around 5 maximum.



Thanks everyone!
 
Don't really understand what you want. You just want to output the modifier value with indentation equal to the level value?

Jon

"I don't regret this, but I both rue and lament it.
 
Yeah thats right, loop through the modifiers, and for each level indent it a little bit more
 
Something like this?
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:template match="/">
    <html>
      <head>
        <title>Test</title>
      </head>
      <body>
        <xsl:apply-templates select="root/child"/>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="child">
    <div style="padding-left: {level * 20}px">
      <xsl:text>-</xsl:text>
      <xsl:value-of select="modifier"/>
    </div>
  </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