Project

Profile

Help

XSLT 3 stylesheet using apply-templates select="descendant::item" passes streamability analysis but gives "XTSE3430: Template rule is not streamable" during execution

Added by Martin Honnen about 6 years ago

While trying to use streaming in XSLT 3 I have created a stylesheet that passes the streamability analysis in Saxon 9.8 and 9.9 EE but then during execution gives an error

XTSE3430: Template rule is not streamable

  • In a streaming apply-templates instruction, the select expression must not have crawling posture (for example, it cannot select descendants)

The code has causing the problem has

    <xsl:template match="/">
        <xsl:variable name="lines" as="xs:string*">
            <xsl:apply-templates select="descendant::item"/>
        </xsl:variable>
        <xsl:value-of select="distinct-values($lines)" separator="&#10;"/>
    </xsl:template>

and I can fix the problem and get the wanted output by using outermost(descendant::item) instead in the select expression of the apply-templates but I guess something is wrong if the streamability analysis doesn't reject the code but the run-time code then rejects the code as not being streamable, so I report the issue here.

Complete reduced example XSLT is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math"
    exclude-result-prefixes="#all"
    version="3.0">
    
    <xsl:mode streamable="yes"/>
    
    <xsl:output method="text"/>
    
    <xsl:template match="/">
        <xsl:variable name="lines" as="xs:string*">
            <xsl:apply-templates select="descendant::item"/>
        </xsl:variable>
        <xsl:value-of select="distinct-values($lines)" separator="&#10;"/>
    </xsl:template>
    
    <xsl:template match="item">
        <xsl:apply-templates select="copy-of()" mode="line"/>
    </xsl:template>
    
    <xsl:template match="item" as="xs:string" mode="line">
        <xsl:value-of select="foo, bar" separator="|"/>
    </xsl:template>
    
</xsl:stylesheet>

sample XML is

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <record>
        <header1>r1h1</header1>
        <header2>r1h2</header2>
        <item>
            <foo>i1foo</foo>
            <bar>i1bar</bar>
        </item>
    </record>
    <record>
        <header1>r1h1</header1>
        <header2>r1h2</header2>
        <item>
            <foo>i1foo</foo>
            <bar>i1bar</bar>
        </item>
    </record>
    <record>
        <header1>r2h1</header1>
        <header2>r2h2</header2>
        <item>
            <foo>i2foo</foo>
            <bar>i2bar</bar>
        </item>
    </record>
    <record>
        <header1>r3h1</header1>
        <header2>r3h2</header2>
        <item>
            <foo>i3foo</foo>
            <bar>i3bar</bar>
        </item>
    </record>
</root>

Output of Saxon 9.9 EE is

Saxon-EE 9.9.0.1J from Saxonica
Java version 1.8.0_181
Using license serial number V...
Saxon evaluation license expires in 9 days
Stylesheet compilation time: 320.948321ms
Processing file:/C:/SomePath/input1.xml
Streaming file:/C:/SomePath/input1.xml
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Error on line 12 of apply-templates-desc-in-var2.xsl:
  XTSE3430: Template rule is not streamable
  * In a streaming apply-templates instruction, the select expression must not have
  crawling posture (for example, it cannot select descendants)

Replies (2)

RE: XSLT 3 stylesheet using apply-templates select="descendant::item" passes streamability analysis but gives "XTSE3430: Template rule is not streamable" during execution - Added by Martin Honnen about 6 years ago

Looking at it again I perhaps just have a wrong recollection that Saxon used to first compile the stylesheet and do the streamability analysis and only if it succeeded start processing the input?

If I add the option --strictStreamability:on then Saxon clearly tells me

Static error at xsl:template on line 12 column 29 of apply-templates-desc-in-var2.xsl: XTSE3430: Template rule is not guaranteed-streamable

although still after outputting the "Processing/Streaming file ..." messages. So it seems the streamability analysis works and the order of messages just confused me to believe there is something wrong.

RE: XSLT 3 stylesheet using apply-templates select="descendant::item" passes streamability analysis but gives "XTSE3430: Template rule is not streamable" during execution - Added by Michael Kay about 6 years ago

I suspect the problem here is JIT compilation of template rules, whereby static analysis of a template rule is deferred until the first time the rule is executed. Although -jit:on is the default, I would suggest switching it off during development and on during production, so that static errors are always detected eagerly while the code is under development.

    (1-2/2)

    Please register to reply