[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: How to parse recursive DOM object


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
  • Xalan problem
    • Daniel Malone - Wed, 12 Jul 2000 13:55:05 -0400
      • sivaji - Thu, 13 Jul 2000 17:20:08 -0700
        • Jeni Tennison - Fri, 14 Jul 2000 11:16:48 +0100 <=
        • sivaji - Fri, 21 Jul 2000 09:47:23 -0700