[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: node depth
Bernie wrote:
Is there any way to find out the depth of the current element in a The depth of any node in the current tree can be requested with: count(ancestor-or-self::*) Bonus: your stylesheet can be written a bit easier as follows: <xsl:template match="section"> <li> <xsl:apply-templates select="label" /> </li> <ul> <xsl:apply-templates select="section" /> </ul> </xsl:template> <xsl:template match="label"> <xsl:apply-templates select="@href[@href != '']" /> <xsl:value-of select=".[not(@href) | normalize-space(@href) = '']" /> </xsl:template> <xsl:template match="label/@href"> <a href="{.}"><xsl:value-of select="label" /></a> </xsl:template> As a general hint, whenever you are writing an xsl:choose or an xsl:if with a node test, consider rewriting it as a matching template/applying templates pair. This will undoubtedly make your code more adept to change, efficient and easier to understand in the long run. A test for a label being empty and then outputting its value is unnecessary. It may happen that an empty <a></a> occurs but that still renders the same, if you don't like that you can remove it by changing the matching template to: <xsl:template match="label[.!='']/@href"> <a href="{.}"><xsl:value-of select="label" /></a> </xsl:template> Cheers, Abel Braaksma
|
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
|