|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: how to get the position of first special element?
----- Original Message -----
From: "Chen Yi" <chen_yi36@xxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Sunday, June 06, 2004 10:06 AM Subject: how to get the position of first special element? ALL,This will do but I'm sure there's a more elegant solution: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:value-of select="count((element/*[name() = 'C' or name() = 'D'])[1]/preceding-sibling::*) + 1"/> </xsl:template> </xsl:stylesheet> One trap, if there aren't any matches this will give the wrong result, you may wish to test for any matches first: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:variable name="CDnode" select="(element/*[name() = 'C' or name() = 'D'])[1]"/> <xsl:choose> <xsl:when test="$CDnode"> <xsl:value-of select="count($CDnode/preceding-sibling::*) + 1"/> </xsl:when> <xsl:otherwise> No matches </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> -- Joe (MVP - xml)
|
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








