Project

Profile

Help

Bug #5042

closed

xslt3 fails to identify that function with type declaration as="element()" returns an empty sequence

Added by Martin Honnen over 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
XX compiler
Sprint/Milestone:
-
Start date:
2021-07-18
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

I have a function with a return type declaration as="element()" but a body, that, after a code change and the use of xsl:where-populated, might return the empty sequence.

In this case Saxon Java or Saxon-JS when running a compiled stylesheet from Saxon Java EE give the error "XTTE0780".

However, when I run the stylesheet directly through xslt3, i.e. use the XX compiler, the error is not noticed and the stylesheet incuding the function call returning an empty sequence is executed.

Example function:

    <xsl:function name="mf:wrap-if-populated" as="element()" visibility="public">
        <xsl:param name="items" as="item()*"/>
        <xsl:param name="wrapper-name" as="xs:QName"/>
        <xsl:where-populated>
            <xsl:element name="{$wrapper-name}" namespace="{namespace-uri-from-QName($wrapper-name)}">
                <xsl:apply-templates select="$items"/>
            </xsl:element>      
        </xsl:where-populated>
    </xsl:function>

Full test case

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:mf="http://example.com/mf"
    exclude-result-prefixes="#all"
    expand-text="yes">
    
    <xsl:function name="mf:wrap-if-populated" as="element()" visibility="public">
        <xsl:param name="items" as="item()*"/>
        <xsl:param name="wrapper-name" as="xs:QName"/>
        <xsl:where-populated>
            <xsl:element name="{$wrapper-name}" namespace="{namespace-uri-from-QName($wrapper-name)}">
                <xsl:apply-templates select="$items"/>
            </xsl:element>      
        </xsl:where-populated>
    </xsl:function>
    
    <xsl:template match="list[@type = 'ordered']">
        <xsl:sequence select="mf:wrap-if-populated(item, QName('', 'ol'))"/>
    </xsl:template>
    
    <xsl:template match="list">
        <xsl:sequence select="mf:wrap-if-populated(item, QName('', 'ul'))"/>
    </xsl:template>
    
    <xsl:template match="list/item">
        <li>
            <xsl:apply-templates/>
        </li>
    </xsl:template>
    
    <xsl:template match="root">
        <html>
            <head>
                <title>Example</title>
            </head>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:mode on-no-match="shallow-copy"/>
    
    <xsl:template match="/" name="xsl:initial-template">
        <xsl:next-match/>
        <xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment>
    </xsl:template>
    
</xsl:stylesheet>

Sample input:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <list>
        <item>a</item>
        <item>b</item>
        <item>c</item>
    </list>
    <list type="ordered"></list>
</root>

Output of xslt3 when running the SEF compiled by Saxon Java EE 10.5:

<?xml version="1.0" encoding="UTF-8"?>
<html>
   <head>
      <title>Example</title>
   </head>
   <body>
      <ul>
         <li>a</li>
         <li>b</li>
         <li>c</li>
      </ul>Transformation failure: Error XTTE0780 at sheet2.xsl#13
    Required cardinality of result of call to function mf:wrap-if-populated#2 is exactly one; supplied value is empty
Error XTTE0780 at sheet2.xsl#13
    Required cardinality of result of call to function mf:wrap-if-populated#2 is exactly one; supplied value is empty

Output when running the XSLT file through xslt3:

<?xml version="1.0" encoding="UTF-8"?>
<html>
   <head>
      <title>Example</title>
   </head>
   <body>
      <ul>
         <li>a</li>
         <li>b</li>
         <li>c</li>
      </ul>
   </body>
</html>
<!--Run with Saxon-JS 2.2 Node.js-->

Please register to edit this issue

Also available in: Atom PDF Tracking page