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

RE: sum

Subject: RE: sum
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Wed, 4 Feb 2004 11:25:56 -0800
xsl sum
>  <xsl:template name="substream8" match="m:SUBSTR8">
>        <xsl:value-of 
>  select="sum(number((substring-after(normalize-space(./m:SUBSTREAM/m:SUBSTREAM_interior),' 
>  '))))"/>
>  </xsl:template>

The XPath sum function takes a nodeset, and not a number. See http://www.w3.org/TR/xpath#function-sum

Accessing the first GOP_BYTE can be done by using the [1] predicate, which is equivalent to [position() = 1]. Determining the path to the GOP_SIZE element that contains the GOP_BYTE elements depends on your context, so 

I made your XML valid by wrapping it in a <doc> element, and terminating the <SUBSTR8> element. This XSLT uses two methods to get your result, one using exst:node-set and the other using a recursive template. 


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 

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

<xsl:template match="/doc">

<xsl:variable name="rtf">
  <xsl:for-each select="SUBSTR8/SUBSTREAM/SUBSTREAM_interior">
    <x><xsl:value-of select="substring-after(.,' ')"/></x>

<xsl:variable name="sum-by-nodeset" select="sum(exslt:node-set($rtf)/x)"/>

<xsl:variable name="sum-by-template">
  <xsl:call-template name="sum-SUBSTREAM_interior">
    <xsl:with-param name="the-substream" select="SUBSTR8/SUBSTREAM[1]"/>

  <xsl:value-of select="GOPSIZE/GOP_BYTE[1]"/> -
  <xsl:value-of select="$sum-by-nodeset"/> =
  <xsl:value-of select="GOPSIZE/GOP_BYTE[1] - $sum-by-nodeset"/>
  <xsl:value-of select="GOPSIZE/GOP_BYTE[1]"/> -
  <xsl:value-of select="$sum-by-template"/> =
  <xsl:value-of select="GOPSIZE/GOP_BYTE[1] - $sum-by-template"/>


<xsl:template name="sum-SUBSTREAM_interior">
  <xsl:param name="value" select="0"/>
  <xsl:param name="the-substream"/>

  <xsl:variable name="the-sum">
      <xsl:when test="$the-substream/following-sibling::SUBSTREAM">
        <xsl:call-template name="sum-SUBSTREAM_interior">
          <xsl:with-param name="value" 
              select="number(substring-after($the-substream/SUBSTREAM_interior,' '))"/>
          <xsl:with-param name="the-substream" 
        <xsl:value-of select="number(substring-after($the-substream/SUBSTREAM_interior,' '))"/>

  <xsl:value-of select="$the-sum + $value"/>


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of poppe chris
Sent: Wednesday, February 04, 2004 3:56 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  sum

Hello, i have the following question,

Im dealing with the following xmlfile (only showing parts of it)


                <SUBSTREAM_interior>477407 1447</SUBSTREAM_interior>
	<SUBSTREAM_interior>478856 4691</SUBSTREAM_interior>
	<SUBSTREAM_interior>483549 14894</SUBSTREAM_interior>
	<SUBSTREAM_interior>498447 60422</SUBSTREAM_interior>
	<SUBSTREAM_interior>558873 233080</SUBSTREAM_interior>

what i would like to do is take the sum of all the rightparts of the 
<SUBSTREAM_interior> elements and substract this from the first <GOP_BYTE> 
element. 2 problems arise here, first of all,
how can i take a sum of those elements?

I use number((substring-after(normalize-space(m:SUBSTREAM_interior),' ')))  
to reach the right part of the <SUBSTREAM_interior> but something like

<xsl:template name="substream8" match="m:SUBSTR8">

doesnt work,

and secondly when i got the sum how can i substract it from a 
<GOP_BYTE>element wich is standing higher in the xmlfile then the <SUBSTR8> 

I hope someone can help me out here,

greetings Chris

Geschenkideeën en e-cards voor Valentijn ! http://www.msn.be/valentijn

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread
  • sum
    • poppe chris - Wed, 4 Feb 2004 06:56:44 -0500 (EST)
      • <Possible follow-ups>
      • Josh Canfield - Wed, 4 Feb 2004 14:26:35 -0500 (EST) <=


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.
First Name
Last Name
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.