|
Subject: Re: [xsl] 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 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Which XSL DTD to use and how , Uri Goldstein | Thread | [xsl] what is <xsl:eval no entries=, Sachidanandam E.K |
| [xsl] Saxon 6.0.2 : How does it han, Ted Rice | Date | [xsl] Tagless XSL Authoring??, Bill |
| Month |