Re: [xsl] Fw: problem with sum() function

Subject: Re: [xsl] Fw: problem with sum() function
From: "Pankaj Bishnoi" <pankaj.bishnoi@xxxxxxxxxxx>
Date: Tue, 27 Jun 2006 13:36:16 +0530
Thanks for the help Michael. I have found the solution the correct xsl is::

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.1" xmlns:java="http://xml.apache.org/xslt/java";
xmlns:str="http://exslt.org/strings";
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
 xmlns:xalan="http://xml.apache.org/xalan";
extension-element-prefixes="redirect">
     <xsl:output method="xml" version="1.0" encoding="ISO-8859-1"
indent="yes"/>
     <xsl:template match="/">
          <Root>
               <xsl:apply-templates
select="/Root/CLIENT_HEADER_RECORD_TYPE-HT"
mode="_Root_Record_order1"></xsl:apply-templates>
          </Root>
     </xsl:template>
     <xsl:template match="/Root/CLIENT_HEADER_RECORD_TYPE-HT"
mode="_Root_Record_order1">
          <Record>
               <xsl:variable name="varClientNumber" select="CLIENT_NUMBER"/>
               <xsl:variable name="varCTDCSibling" select="count(following::
CLAIM_SETUP_CHANGE_RECORD_TYPE-CT[CLAIM_SETUP_CHANGE_RECORD_TYPE =
&apos;CT&apos; and DATA_TYPE = &apos;DC&apos; and
CLIENT_NUMBER=$varClientNumber])"/>
               <xsl:variable name="varETDCSibling"
select="following::EXPERIENCE_SETUP_CHANGE_RECORD_TYPE-ET[DATA_TYPE =
&apos;DC&apos; and CLIENT_NUMBER=$varClientNumber]/EXPER_AMT_BY_RESERVE1"/>
  <xsl:variable name="xml-subset">
         <xsl:for-each select="$varETDCSibling">
              <a>
              <xsl:value-of select="number(translate(. ,'+',''))"/>
            </a>
            </xsl:for-each>
  </xsl:variable>

               <ErrorMessage><xsl:value-of
select="sum(xalan:nodeset($xml-subset)//a)"/></ErrorMessage>
                          <CTDC>
                    <xsl:value-of select="$varCTDCSibling"/>
               </CTDC>
                 </Record>
     </xsl:template>
</xsl:stylesheet>


----- Original Message ----- 
From: "Michael Kay" <mike@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, June 26, 2006 10:03 PM
Subject: RE: [xsl] Fw: problem with sum() function


> > > Hi All
> > >          I am using sum() function with nodelist. Now my
> > problem is that
> > > when a source elemnt contains leading + sign then sum
> > returns NAN. Is
> > there
> > > a way to remove this + sign and then calculate the sum.
>
> Google for "XSLT 1.0 sum of computed value".
>
> XSLT 2.0 allows the leading plus sign; and if it didn't, you could do it
> with
>
> sum(for $x in $nodeset return number(translate($x, '+', ''))
>
> Michael Kay
> http://www.saxonica.com/

Current Thread