|
Subject: Re: How to parse recursive DOM object From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx> Date: Fri, 14 Jul 2000 11:16:48 +0100 |
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@xxxxxxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| How to parse recursive DOM object, sivaji | Thread | Re: How to get the parent node in a, sivaji |
| Skipping elements for conversion fr, Vinay Jaiswal | Date | Re: Skipping elements for conversio, Jeni Tennison |
| Month |