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(_at_)gmx(_dot_)net]
Sent: 29 May 2005 11:36
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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 +++
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--