[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Counting and Rearranging Nodes

Subject: Re: Counting and Rearranging Nodes
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sat, 24 Jun 2006 11:01:28 +0530
rostom co
Sorry about that. Please try this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" />

   <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 &gt; 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>

</xsl:stylesheet>

Regards,
Mukul

On 6/23/06, rostom aghanian <rostom@xxxxxxxx> wrote:
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.