This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to parse recursive DOM object
- To: sivaji <sivaji at panop dot com>
- Subject: Re: How to parse recursive DOM object
- From: Jeni Tennison <Jeni dot Tennison at epistemics dot co dot uk>
- Date: Fri, 14 Jul 2000 11:16:48 +0100
- Cc: xsl-list at mulberrytech dot com
- References: <8525691A.00626DFE.00@lndanmta01.pb.com>
- Reply-To: xsl-list at mulberrytech dot com
Sivaji,
>I am facing problem in parsing recursive dom object , how to get the
nested level,
>and the levels at different levels
You can find out the depth of the current node within a nested structure by
counting the number of ancestors of that node using the following XPath:
count(ancestor::*)
In the following stylesheet, I use a variable to store that information and
to construct the lines that you want.
<xsl:template match="root">
folderTree = gFld("<xsl:value-of select="normalize-space(text()[1])" />"
, "" )
<xsl:apply-templates />
</xsl:template>
<xsl:template match="cat|child">
<xsl:variable name="depth" select="count(ancestor::*)" />
aux<xsl:value-of select="$depth" /><xsl:text> = insFld(</xsl:text>
<xsl:choose>
<xsl:when test="$depth = 1">folderTree</xsl:when>
<xsl:otherwise>aux<xsl:value-of select="$depth - 1" /></xsl:otherwise>
</xsl:choose>
<xsl:text>, gFld("</xsl:text><xsl:value-of
select="normalize-space(text()[1])" />", ""))
<xsl:apply-templates />
</xsl:template>
Tested and works on SAXON.
I hope that helps,
Jeni
Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 • Fax 0115 9061304 • Email
jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list