[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting an xml to another xml Using XSLT

Subject: RE: Converting an xml to another xml Using XSLT
From: "Tedla, Sridhar \(LNG-CSP\)" <Sridhar.Tedla@xxxxxxxxxxxxxx>
Date: Tue, 2 May 2006 15:10:26 -0600
converting xml tree to another
Thank You for the solution.

-----Original Message-----
From: Jon Gorman [mailto:jonathan.gorman@xxxxxxxxx]
Sent: Tuesday, May 02, 2006 2:48 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Converting an xml to another xml Using XSLT

> I need suggestion or solution how to handle arbitary depth i.e. if
> "classitem" depth is 5 or 8 or some other value.
>
Right.....but the confusion is why you're checking for the depth anyhow.
The entire point of XSLT is that the processor can do the work of
traveling for the tree for you.  If you always do the same thing
regardless of depth, just put it into one template.  To repeat my code
templates before (with them cleaned up a little):

<xsl:template match="class">
<hier>
<xsl:apply-templates />
</hier>
</xsl:template>

<xsl:template match="classitem">
<hierlev>
<heading>
  <title><xsl:value-of select="identifier/name" /></title> </heading>
<xsl:apply-templates /> </hierlev> </xsl:template>

<xsl:template match="identifier" />
<xsl:template match="code" />

Given these templates, the code will always produce <hierlev> <heading>
<title>name</title> </head> ...whatever output applying templates to
children element <hierlev>

when it sees a classitem element.


XSLT by default uses recursive travel of the document tree.

Now, a variation might be that you need to do something different based
off the depth of the element in the tree.  Off the top of my head
counting the nodes in the ancestor axis would be the way to do that.


Jon Gorman

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.