Project

Profile

Help

xml-to-json function in Saxon 9.9.1.1 EE not streamable?

Added by Martin Honnen over 5 years ago

I tried a simple test case with Saxon 9.9.1.1 EE inside of oXygen simply calling xml-to-json in the template matching the document node of the primary input document processed with a streamable mode and I get an error

Engine name: Saxon-EE 9.9.1.1 (External)
Severity: error
Description: Template rule is not streamable * Operand {.} of {fn:xml-to-json(...)} selects streamed nodes in a context that allows arbitrary navigation (line 13)

while the same code with Saxon 9.8.0.12 EE works fine inside of oXygen and from the command line.

Example stylesheet 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="xs math"
    version="3.0">
    
    <xsl:mode streamable="yes"/>
    
    <xsl:output method="text"/>
    
    <xsl:template match="/">
        <xsl:value-of select="xml-to-json(., map { 'indent' : true()  })"/>
    </xsl:template>
    
</xsl:stylesheet>

Seems to happen with any input, for instance the XML sample from the XSLT 3 spec

<?xml version="1.0" encoding="UTF-8"?>
<map xmlns="http://www.w3.org/2005/xpath-functions">
    <string key='desc'>Distances between several cities, in kilometers.</string>
    <string key='updated'>2014-02-04T18:50:45</string>
    <boolean key="uptodate">true</boolean>
    <null key="author"/>
    <map key='cities'>
        <array key="Brussels">
            <map>
                <string key="to">London</string>
                <number key="distance">322</number>
            </map> 
            <map>
                <string key="to">Paris</string>
                <number key="distance">265</number>
            </map> 
            <map>
                <string key="to">Amsterdam</string>
                <number key="distance">173</number>
            </map> 
        </array>
        <array key="London">
            <map>
                <string key="to">Brussels</string>
                <number key="distance">322</number>
            </map> 
            <map>
                <string key="to">Paris</string>
                <number key="distance">344</number>
            </map> 
            <map>
                <string key="to">Amsterdam</string>
                <number key="distance">358</number>
            </map> 
        </array>
        <array key="Paris">
            <map>
                <string key="to">Brussels</string>
                <number key="distance">265</number>
            </map> 
            <map>
                <string key="to">London</string>
                <number key="distance">344</number>
            </map> 
            <map>
                <string key="to">Amsterdam</string>
                <number key="distance">431</number>
            </map>  
        </array>
        <array key="Amsterdam">
            <map>
                <string key="to">Brussels</string>
                <number key="distance">173</number>
            </map> 
            <map>
                <string key="to">London</string>
                <number key="distance">358</number>
            </map> 
            <map>
                <string key="to">Paris</string>
                <number key="distance">431</number>
            </map>
        </array>
    </map>  
</map>

Is that an intended change in 9.9?


Replies (1)

RE: xml-to-json function in Saxon 9.9.1.1 EE not streamable? - Added by Michael Kay over 5 years ago

I found it failed only with the 2-argument form of xml-to-json(), and that could be corrected by changing the operand usage in the table of function signatures.

But the puzzle then becomes, why was test sf-xml-to-json-002 working?

The answer is that it -- and several other of the tests in the sf-xml-to-json test set -- were using xsl:source-document without specifying streamable="yes", so they were actually running without streaming, and thus not testing anything useful. I have corrected these tests (and am raising a Saxon issue).

Saxon 9.8 has the same coding error as Saxon 9.9, but I won't investigate why it is apparently working when it is wrong.

    (1-1/1)

    Please register to reply