Subject: Re: [xsl] Recursion of variable From: "watchstone@xxxxxxxxxxx" <watchstone@xxxxxxxxxxx> Date: Fri, 19 Aug 2005 23:40:00 GMT |
Darn! Another glitch. David's code works perfectly, except when <cnt> = 1. In this case, the output should not be a range but a single digit. I honestly tried to fix it myself, but couldn't garner enough brain cells to figure it out: XML: <vector> <r1> <t>geometry</t> <r2> <t>parabola</t> <r3> <t>trapezium</t> <cnt>4</cnt> </r3> <r3> <t>rhombus</t> <cnt>4</cnt> </r3> </r2> <r2> <t>parallelogram</t> <cnt>1</cnt> </r2> </r1> <r1> <t>reflection</t> <cnt>1</cnt> </r1> </vector> Desired output: <vector> <r1> <t>geometry</t> <r2> <t>parabola</t> <r3> <t>trapezium</t> <o>1-5</o> (This is the value 1 + <cnt>, carry value "6" forward) </r3> <r3> <t>rhombus</t> <o>6-10</o> (This is the value 6 + <cnt>, carry value "11" forward) </r3> </r2> <r2> <t>parallelogram</t> <o>11</o> (This is the value 11 carried forward, but since <cnt> = 1, don't sum, carry value "12" forward) </r2> </r1> <r1> <t>reflection</t> <o>12</o> (This is the value 12 carried forward, same as above, don't sum) </r1> </vector> -- David Carlisle <davidc@xxxxxxxxx> wrote: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="cnt"> <xsl:variable name="cs" select="preceding::cnt"/> <xsl:variable name="c" select="1+sum($cs)+count($cs)"/> <o><xsl:value-of select="$c"/>-<xsl:value-of select="$c + ."/></o> </xsl:template> </xsl:stylesheet> ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Recursion of variable, watchstone@xxxxxxxxx | Thread | [xsl] Help regarding displaying anc, Singh, Revant |
[xsl] lightweight counterpart for c, Manfred Staudinger | Date | [xsl] Fw: Calling Nodes in XSL, jeb501 |
Month |