[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] [XSLT2] Different results using xsl:copy-of and xsl:sequence with Saxon 7.8


Subject: [xsl] [XSLT2] Different results using xsl:copy-of and xsl:sequence with Saxon 7.8
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 14 Nov 2003 22:42:38 +0100

I have this code:

func-allTrue.xsl:
------------------
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fxl="http://fxsl.sf.net/"
xmlns:allTrue-And="allTrue-And"
exclude-result-prefixes="fxl xs allTrue-And"
>
  <xsl:import href="func-foldl.xsl"/>

  <xsl:function name="fxl:allTrue" as="xs:boolean" >
    <xsl:param name="pList" as="xs:boolean*"/>

    <xsl:variable name="vAnd" select="document('')/*/allTrue-And:*[1]"/>

    <xsl:copy-of select="fxl:foldl($vAnd, true(), $pList)"/>
  </xsl:function>

  <allTrue-And:allTrue-And/>
  <xsl:template name="And" match="allTrue-And:*" as="xs:boolean">
    <xsl:param name="arg1" as="xs:boolean"/>
    <xsl:param name="arg2"  as="xs:boolean"/>
    <xsl:sequence select="$arg1 and $arg2"/>
  </xsl:template>

</xsl:stylesheet>

This stylesheet defines an xsl:function fxl:allTrue

I apply the allTrue function as follows:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:fxl="http://fxsl.sf.net/"
 exclude-result-prefixes="fxl xs"
>
  <xsl:import href="func-allTrue.xsl"/>

  <xsl:output omit-xml-declaration="yes"/>

  <!-- This transformation must be applied to:
        boolNodes.xml
     -->

  <xsl:template match="/">
    <xsl:variable name="allTrue"
         select="fxl:allTrue(/*/*/text())"/>

    <xsl:value-of select="$allTrue"/>

    <xsl:if test="not($allTrue)">
      <xsl:text>Not </xsl:text>
    </xsl:if>
    <xsl:value-of select="'all nodes contents are true in:'"/>
    <xsl:text>&#xA;</xsl:text>
    <xsl:copy-of select="/*/*"/>
  </xsl:template>
</xsl:stylesheet>

When applied on this source.xml:

<t>
  <a>1</a>
  <b>1</b>
  <c>0</c>
  <d>1</d>
</t>

the correct result is produced:

falseNot all nodes contents are true in:
<a>1</a><b>1</b><c>0</c><d>1</d>


The problem:

In the code of allTrue I replace xsl:copy-of with xsl:sequence like this:

      <xsl:copy-of select="fxl:foldl($vAnd, true(), $pList)"/>

with

    <xsl:sequence select="fxl:foldl($vAnd, true(), $pList)"/>

I run the same test again and get a dynamic error:

"Dynamic error in function fxl:allTrue
Dynamic error in function fxl:allTrue
Error at variable on line 17 of
file:/E:/xml/msxml/XML%20SDK/Samples/Tests/Generic/FP/Fxsl/XSLT2/marrowtr.xsl:
  Required type of result of function fxl:allTrue is xs:boolean; supplied
value is java:java.lang.Object
Transformation failed: Run-time errors were reported"

My questions:

What is actually happening here? Is this difference in the behaviour of
xsl:copy and xsl:sequence documented in the WD?
Am I not understanding and using xsl:sequence in a correct way or is this a
bug in the XSLT processor?



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL









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



Current Thread
Keywords