[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: number continuation problem
David wrote: >> The way Ive resolved it is to build a temporary tree that flattens >> out the hierarchy to a single level, > > yes I was going to suggest the same (unless Jeni rises to the > challenge of doing it in one pass:-) Well, I think you can do it with the following, though it's a bit tedious if you have a big document because you need to work out the number of the previous node to work out this one: <xsl:template match="node" mode="number"> <xsl:choose> <xsl:when test="preceding::node"> <xsl:variable name="number"> <xsl:choose> <xsl:when test="not(preceding-sibling::node)"> <xsl:choose> <xsl:when test="parent::if"> <xsl:variable name="else" select="preceding::node[1]/parent::else" /> <xsl:choose> <xsl:when test="$else"> <xsl:variable name="if-number"> <xsl:apply-templates select="$else/preceding-sibling::if[1]/node[last()]" mode="number" /> </xsl:variable> <xsl:variable name="else-number"> <xsl:apply-templates select="preceding::node[1]" mode="number" /> </xsl:variable> <xsl:choose> <xsl:when test="$if-number > $else-number"> <xsl:value-of select="$if-number" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$else-number" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="preceding::node[1]" mode="number" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:variable name="number"> <xsl:apply-templates select="parent::else/preceding-sibling::if[1]/node[1]" mode="number" /> </xsl:variable> <xsl:value-of select="$number - 1" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="preceding::node[1]" mode="number" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:value-of select="$number + 1"/> </xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:template> I was thinking about a recursive solution that would step through the <node> elements one-by-one, but the nested <if>s make it pretty difficult. Anyway, I'm sure that flattening is a much better approach... Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ 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
|