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

Re: XSL 1.0 - sum values taken from corresponding colu

Subject: Re: XSL 1.0 - sum values taken from corresponding column
From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 12 Feb 2015 17:12:56 -0000
Re:  XSL 1.0 - sum values taken from corresponding colu
I think that in XSLT 1 the only solution would be to use sibling recursion:

<xsl:template name="sumcells">
  <xsl:param name="inSum"/>
  <xsl:variable name="sum" select="$inSum + number(.)"/>
  <xsl:choose>
    <xsl:when test="count(following-sibling::cell) = 0">
      <xsl:value=of select="$sum"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:for-each select="following-sibling:cell[1]">
       <xsl:with-param name="inSum" select="$sum"/>
     </xsl:for-each>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Cheers,

E.

bbbbb
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com




On 2/12/15, 5:42 AM, "Kevin Bird kevinbrianbird@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>Hello,
>
>In <col2>, where cell = num, return the corresponding col1/cell/@value,
>summing the result.
>
><root>
>	<col1>
>		<cell value="1">text</cell>
>		<cell value="12">text</cell>
>		<cell value="24">text</cell>
>		<cell value="100">text</cell>
>		<cell value="9">text</cell>
>		<cell value="6">text</cell>
>	</col1>
>	<col2>
>		<cell>num</cell>
>		<cell>-</cell>
>		<cell>num</cell>
>		<cell>-</cell>
>		<cell>num</cell>
>		<cell>num</cell>
>	</col2>
>	<col3>
>		<cell>-</cell>
>		<cell>num</cell>
>		<cell>num</cell>
>		<cell>num</cell>
>		<cell>num</cell>
>		<cell>-</cell>
>	</col3>
></root>
>
>Sum for <col2> is: 40
>
>Sum for <col3> is: 145
>
>I'd like an XPath solution, but I don't think that is possible.
>
>I tried using keys.
>
><xsl:key name="byValue" match="cell" use="/root/col1/cell[position() =
>count(current()/preceding-sibling::cell)+1]/@value"/>
>
>So each cell has the correct value, but I'm struggling to sum the values.
>Maybe my thinking is wrong.
>
>Any help appreciated.
>
>--
>Kevin

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.