|
Subject: Re: [xsl] sequence as function parameter From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 04 Jul 2011 11:06:09 -0400 |
I am trying to create a simple function to multiply each item in a sequence by each other (like a sum()). My problem is that I am unable to have the parameter treated as a node sequence (using saxon, so XSL2.0)
I have <xsl:template name=" multiplie">
<xsl:param name="serie"/>
<xsl:param name="result" as="xs:double"/>
<!--some test output -->
<xsl:value-of select="$serie"/>-<xsl:value-of
select="$result"/>--
###<xsl:value-of select="count($serie)"/>###
<!-- -->
<xsl:choose>
<xsl:when test="count($serie) gt 1">
<!-- make the multiplication between result and
the first item in the serie, then remove it and call again -->
<xsl:variable name="comp">
<xsl:value-of select="number($serie[1])
* $result"/>
</xsl:variable>
<xsl:call-template name=" multiplie">
<xsl:with-param name="serie"><xsl:copy-of
select="subsequence($serie,2)"/></xsl:with-param>
<xsl:with-param name="result"><xsl:value-of select="$comp"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($serie[1]) *
$result"/>
... So, the part where I do a count gets me 1, when I should have 4... I have tried with <xsl:param name="serie" as="node()*"/> but I have an error message XTTE0790: Required item type of first argument of multiplie() is node(); supplied value has item type xs:double
I am a bit out of ideas....
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="urn:X-Fabien" version="2.0">
<xsl:template match="/"> ?<xsl:variable name="seq" select="(6.8E-06,5.5E-06,7.1E-06,7.3E-06)"/> Fabien's test: <xsl:value-of select="f:multiplie($seq)"/> Ken's tests: <xsl:value-of select="f:multiplie((7))"/> and: <xsl:value-of select="f:multiplie((1,2,3,4,5))"/> </xsl:template>
<xsl:function name="f:multiplie">
<xsl:param name="seq" as="item()+"/><!--at least one item in sequence-->
<xsl:sequence select="if( count($seq)=1 ) then $seq
else $seq[1] * f:multiplie($seq[position()>1])"/>
</xsl:function>
</xsl:stylesheet>-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] sequence as function para, Fabien Tillier | Thread | RE: [xsl] sequence as function para, Fabien Tillier |
| Re: [xsl] sequence as function para, David Carlisle | Date | RE: [xsl] sequence as function para, Fabien Tillier |
| Month |