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

RE: sum function

Subject: RE: sum function
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 29 May 2005 13:21:07 +0100
gml pos
You may have noticed there is another thread running on the same subject -
how to sum over values that are computed from those held in the nodes,
rather than the actual string-values of the nodes. The solutions on offer
include:

(a) create a temporary tree containing nodes holding the values directly,
then sum over the nodes in that temporary tree

(b) a recursive named template

(c) the f:map function in FXSL

(d) the saxon:sum() extension function in Saxon 6.5.3

(e) In XSLT 2.0, sum(for $x in $nodes return number(tokenize($x, ' ')))

(f) In Schema-aware XSLT 2.0, if the type of your gml:Pos nodes is list of
numbers, then the sum() function will do the job directly.

Michael Kay
http://www.saxonica.com/ 
  

> -----Original Message-----
> From: Andreas Schnabl [mailto:Oandie@xxxxxxx] 
> Sent: 29 May 2005 11:36
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  sum function
> 
> Hi there,
> 
> I am trying to sum some coordinates, afterwards I want to 
> format them and
> display the issue. What I need is to summarize the first 
> coordinates with
> the leading 3 and then the second with the leading 5. 
> I tried the following but it didn't work out. It seems that 
> the processor
> don't use the "substring-before"- elment, cause if I change it into
> "substring- after I got the same display...
> Here comes the code so far: 
> 
> 
> <xsl:template name="x">
> <xsl:variable name="x_sum"
> select="sum(xplan:Position/gml:Polygon/gml:exterior/gml:Linear
> Ring/gml:Pos[substring-before(.,'
> ')])"/>
> <xsl:variable name="x_count"
> select="count(xplan:Position/gml:Polygon/gml:exterior/gml:Line
> arRing/gml:Pos)"/>
> <xsl:variable name="x_format" select="format-number($x_sum, '#')"/>"
> <xsl:variable name="x_rw" select="3400000"/>
> <xsl:variable name="x_ges" select="$x_rw*$x_count"/>
> <xsl:variable name="x_ges1" select="$x_format - $x_ges"/>
> <xsl:variable name="x_ges2" select="$x_ges1 div $x_count"/>
> <xsl:value-of select="$x_sum"/>
> 
> </xsl:template>
> 
> 
> The source looks like this:
> 
> Code:
> 
> (...)
> <gml:Pos>3480252.383 5889479.27</gml:Pos>
> <gml:Pos>3480289.585 5889464.571</gml:Pos>
> (...)
> 
> 
> I changed the position of "substring" in the XPath expression 
> like this:
> 
>  
> 
> <xsl:variable name="x_sum"
> select="sum(substring-before(xplan:Position/gml:Polygon/gml:ex
> terior/gml:LinearRing/gml:Pos,'
> '))"/>
> 
>  
> 
> But then I got only the first value.
> What I need is both of the values inside the gml:Pos element, 
> but apart from
> each other. In the first step I would count all the values which a are
> before the blank and in the second the values after the blank 
> and sum them
> up as well. 
> I need to get the balance point of the values.
> 
>  
> I don't know if it depends maybe on the XSLT- processor I 
> need. I am working
> with XMLSpy, 2005 professinal edition and I use the built in 
> processor.
>  
> 
> cheers
> 
> andy
> 
> 
> -- 
> --------------------------------------------
> GERMANY
> Andreas Schnabl
> Geibelstrasse 2a
> 76185 Karlsruhe
> Tel.:0721- 4903793
> Mob.: 0170-1590394
> --------------------------------------------
> 
> 5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
> +++ GMX - die erste Adresse f|r Mail, Message, More +++

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.