xsl-list
[Top] [All Lists]

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

2003-11-17 13:36:07
Dimitre, could you please send me a repro for this? It's definitely a
bug but I can't easily reproduce it without the full stylesheet.

It's a bug related to tail call optimization. Functions whose body
consists solely of a sequence of xsl:param, xsl:variable, and
xsl:sequence are compiled differently from those that include
instructions like xsl:copy-of, with heavier optimization.

Thanks,

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Dimitre Novatchev
Sent: 14 November 2003 21:43
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] [XSLT2] Different results using xsl:copy-of 
and xsl:sequence with Saxon 7.8


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/XSL
T2/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


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