Subject: Re: [xsl] Counting and Rearranging Nodes From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sat, 24 Jun 2006 11:01:28 +0530 |
<xsl:template match="/Root"> <Root> <xsl:for-each select="Item"> <xsl:sort select="Line_No" data-type="number" /> <New_Item> <xsl:variable name="x" select="substring(Line_No, 1, 1)" /> <xsl:variable name="pow_result"> <xsl:call-template name="pow"> <xsl:with-param name="m" select="10" /> <xsl:with-param name="n" select="string-length(Line_No) - 1" /> <xsl:with-param name="result" select="10" /> </xsl:call-template> </xsl:variable> <Line_No><xsl:value-of select=" ($x * $pow_result) + count(preceding::Line_No[substring(., 1, 1) = $x] )+ 1" /></Line_No> <Line_No_Og><xsl:value-of select=" Line_No" /></Line_No_Og> <Amount><xsl:value-of select="Amount" /></Amount> </New_Item> </xsl:for-each> </Root> </xsl:template>
<!-- Template to calculate m to the power n --> <xsl:template name="pow"> <xsl:param name="m" /> <xsl:param name="n" /> <xsl:param name="result" />
<xsl:choose> <xsl:when test="$n > 1"> <xsl:call-template name="pow"> <xsl:with-param name="m" select="$m" /> <xsl:with-param name="n" select="$n - 1" /> <xsl:with-param name="result" select="$result * $m" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$result" /> </xsl:otherwise> </xsl:choose> </xsl:template>
Regards, Mukul
Thanks Gandi. I tried your stylesheet and it is very good with just one problem: I need the renumbering to begin only for each 100th group; not each 10th group as your stylesheet does. For example:
801 --> 801 (begin 800 group) 802 --> 802 806 --> 803 (notice new Line_No is continuous, wheras original skipped) 814 --> 804 (NOTICE 800 series counting continues as we haven't reached next 100 series yet) 901 --> 901 (notice numbering re-starts at the 1s for a new group (900s)) 944 --> 902 (NOTICE 900 series counting continues as we haven't reached next 100 series yet) 1002 --> 1001 (notice numbering re-starts at the 1s for a new group (1000s)) 1003 --> 1002 (numbering continues consecutively in the 1000's group)
Thanks in advance. rostom
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Counting and Rearranging , rostom aghanian | Thread | [xsl] Use of xsl:document, tom tom |
Re: [xsl] returning nodes (not a st, Dimitre Novatchev | Date | RE: [xsl] Concatenating multiple va, Mohsen Saboorian |
Month |