|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Counting level of nodes beneath current (in XPATH)
Hi all,
I have an XML with the following rules (simplified): X -> Y+ Y -> Z X? Z -> (textnode)
What I am interested in, is the level of Y nodes. If I wanted the top two levels, I could easily do this in xpath using count(ancestor::Y). The problem is that I cannot readily count all descendants - count(descendant::Y) will not count the number of levels but the total number of Y nodes that are beneath the current Y node. Is there a way for such counting in XPath? I want all except the buttom 1, 2, 3 or more levels. The exact amount determined from a parameter. I could have something like [not(X)] for leaf nodes, [not(X/Y/X)] for the the buttom 2 levels (leaf nodes and one level up, counting from the leaf). But as the number of levels are to be determined dynamically, this solution is not the best: <xsl:template match="/">
<xsl:choose>
<xsl:when test="$lv='1'">
<xsl:apply-templates select="Y[not(X)]" mode="One"/>
</xsl:when>
<xsl:when test="$lv='2'">
<xsl:apply-templates select="Y[not(X/Y/X)]" mode="Two"/>
</xsl:when>
...
<xsl:otherwise>
<xsl:apply-templates select="Y" mode="Zero"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><xsl:template match="Y" mode="One"> <!-- Do some stuff --> <xsl:apply-templates select="Y[not(X)]" mode="One"/> </xsl:template>
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
|
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








