|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to parse recursive DOM object
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








