xsl-list
[Top] [All Lists]

RE: [xsl] Calculating cumulative values - another call for help

2007-08-30 08:55:57
Andrew,

When I run your stylesheet against my input I get a Saxon error where it is
creating attribute "y3".  The error is shown below.  The string "n" is the
value of the attribute "id" for the set element in the input.  Is it because
"xs:integer(parent::set/@id - 1)" precludes the use of non-numerical id
values?

Simon

******************************
C:\Program Files\Saxon\bin>transform.exe -t -s testFunc.xml -o
testFuncOutAndrew
2.xml andrew2.xsl
Saxon 8.9N from Saxonica
.NET 2.0.50727.832 on Microsoft Windows NT 5.1.2600 Service Pack 2
Stylesheet compilation time: 797 milliseconds
Processing file:/C:/Program%20Files/Saxon/bin/testFunc.xml
Building tree for file:///C:/Program Files/Saxon/bin/testFunc.xml using
class ne
t.sf.saxon.tinytree.TinyBuilder
Tree built in 15 milliseconds
Tree size: 73 nodes, 97 characters, 60 attributes
Validation error on line 21 of file:///C:/Program
Files/Saxon/bin/andrew2.xsl:
  Cannot convert string "n" to a double
Transformation failed: Run-time errors were reported
******************************

-----Original Message-----
From: Andrew Welch
Sent: August 29, 2007 9:03 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Calculating cumulative values - another call for help

Here's my attempt that uses a key and does it in one pass:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  exclude-result-prefixes="xs">

<xsl:key name="point-by-set-id-and-x" match="point"
  use="concat(parent::set/@id,'-',@x)"/>

<xsl:template match="@*|node()">
        <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
</xsl:template>

<xsl:template match="point">
        <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:attribute name="y2">
        <xsl:value-of select="sum(@y1|preceding-sibling::point[(_at_)x =
current()/@x]/@y1)"/>
        </xsl:attribute>
        <xsl:attribute name="y3">
                <xsl:value-of select="sum((@y1, preceding-sibling::point[(_at_)x
=
current()/@x]/@y1)) + sum(for $x in 1 to xs:integer(parent::set/@id - 1)
return key('point-by-set-id-and-x',
  concat($x, '-', current()/@x))/@y1)"/>
        </xsl:attribute>
        </xsl:copy>
</xsl:template>

</xsl:stylesheet>

It could be re-written in pure 1.0 if you replaced the "for $x in to
xs:integer(parent::set/@id - 1)" with a recursive named template... if you
could be bothered :)

cheers
andrew
--
http://andrewjwelch.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>
--~--



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>