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

Re: Which XSL DTD to use and how do I find the depth o

Subject: Re: Which XSL DTD to use and how do I find the depth of a node relative to the root?
From: Jiri Jirat <Jiri.Jirat@xxxxxxxxx>
Date: Thu, 21 Dec 2000 14:52:06 +0100
best dtd to use
Hello Uri,
 ad 2), I send you a hint, how find the level of nesting.
You must change it a little bit and extract the result
using string functions.

XML:
<a>
 <b>
  <c/>
 </b>
 <b>
  <c>
   <d/>
   <d>
    <e/>
   </d>
   <d/>
  </c>
 </b>
</a>


XSL: (I will determine the level of nesting for /a/b[2]

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:variable name="level">
 <xsl:apply-templates select="b"/>
</xsl:variable>

<xsl:template match="/">
 <xsl:apply-templates select="/a/b[2]"/>
 <xsl:value-of select="$level"/>
</xsl:template>


<xsl:template match="b">
  <xsl:apply-templates select="descendant::*[not(*)]" mode="level">
   <xsl:sort select="count(ancestor::*)" order="descending"
data-type="number"/>
  </xsl:apply-templates>
</xsl:template>


<xsl:template match="*" mode="level">
 <xsl:value-of select="count(ancestor::*)"/>
 <xsl:text>~</xsl:text>
</xsl:template>

</xsl:stylesheet>


And the output is:
4~3~3~

(you must extract the first number, this is the maximum)




Best regards
Jirka




Uri Goldstein wrote:
> 
> Hi There,
> 
>   I have two unrelated questions regarding XSL.
> 
>   One is which XSL DTD should I use  - "http://www.w3.org/TR/WD-xsl"
> or "http://www.w3.org/1999/XSL/Transform"?   How are they different
> and which is newer/better?
> 
>   My second question is what is the way to calculate the depth
> (number of levels below the root) of a node in an XML document
> using XSL?
> 
> Thanks,
> Uri Goldstein,
> Israel
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
 <name firstName="Jirka" surname="Jirat"/>
 <mail>     jiratj@xxxxxxxxx  </mail>
 <support>  http://www.zvon.org </support>
 <zvonMailingList> http://www.zvon.org/index.php?nav_id=4
</zvonMailingList>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.