Re: [xsl] want to display sum of every two records

Subject: Re: [xsl] want to display sum of every two records
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Mon, 22 Feb 2010 09:33:09 +0100
Dear Kumar,

If your input looks like

<?xml version="1.0" encoding="utf-8"?>
<doc>
  <mezo eazon="AA">200</mezo>
  <mezo eazon="AA">50</mezo>
  <mezo eazon="AA">300</mezo>
  <mezo eazon="AA">50</mezo>
</doc>

you may transform it using the following XSLT (2.0):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="2.0"  >

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

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="doc">
    <xsl:copy>
      <xsl:for-each-group select="*"
        group-starting-with="*[position() mod 2 = 1]">
        <xsl:copy-of select="current-group()" />
        <mezo eazon="BB">
          <xsl:value-of select="sum(current-group())"/>
        </mezo>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>


Gerrit



On 22.02.2010 09:09, anil kumar wrote:
Hi,

want to display the column BB as sum of every two records

my o/p should be like below..

<mezo eazon="AA">200</mezo>
<mezo eazon="AA">50</mezo>
<mezo eazon="BB">250</mezo>
<mezo eazon="AA">300</mezo>
<mezo eazon="AA">50</mezo>
<mezo eazon="BB">350</mezo>

iam breaking my head to get the above o/p.

any suggestions ..Can you get it through XSL

Thanks
Kumar


-- Gerrit Imsieke Geschdftsf|hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler

Current Thread