Project

Profile

Help

resolve-uri differences between .xsl and compiled .sef

Added by Martin Honnen over 2 years ago

While trying to understand why Saxon-JS 2.3 fails to compile some XSpec where it uses resolve-uri to construct an xsl:import but gets the resolved URI wrong I constructed a reduced test case and surprisingly found that Saxon 10.5 Java for the .xsl file execution gives the the resolved URI I want but when using EE to first compile to .sef it shows the same difference in the URI that Saxon-JS 2.3 creates.

Test environment has directory resolve-uri-test with subdirectories compiler with subdirectory xslt:

C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\resolve-uri-test>dir compiler

 Verzeichnis von C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\resolve-uri-test\compiler

03.09.2021  11:12    <DIR>          .
03.09.2021  11:12    <DIR>          ..
03.09.2021  11:12             1.918 compile-xslt-tests-HE.xsl.sef
03.09.2021  11:01               486 compile-xslt-tests.xsl
03.09.2021  11:10             1.739 compile-xslt-tests.xsl.sef.json
03.09.2021  10:52    <DIR>          xslt
C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\resolve-uri-test>dir compiler\xslt

 Verzeichnis von C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\resolve-uri-test\compiler\xslt

03.09.2021  10:52    <DIR>          .
03.09.2021  10:52    <DIR>          ..
03.09.2021  10:57               780 main.xsl

File compile-xslt-tests.xsl 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:output indent="yes"/>
    
    <xsl:include href="xslt/main.xsl"/>
    
    <xsl:template name="xsl:initial-template">
        <xsl:call-template name="main"/>
    </xsl:template>
    
</xsl:stylesheet>

File main.xsl 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"
    exclude-result-prefixes="#all"
    version="3.0">
    
    <xsl:template name="main">
        <xsl:element name="xsl:stylesheet">
            <xsl:attribute name="version" select="3.0"/>
            <xsl:attribute name="exclude-result-prefixes">#all</xsl:attribute>
            <xsl:for-each
                select="
                '../../common/runtime-utils.xsl'">
                <xsl:element name="xsl:include">
                    <xsl:attribute name="href" select="resolve-uri(.)" />
                </xsl:element>
            </xsl:for-each>
        </xsl:element>
        
    </xsl:template>
    
</xsl:stylesheet>

Now running Saxon HE or EE Java against the compile-xslt-tests.xsl gives

C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\resolve-uri-test>java -jar "C:\Program Files\Saxonica\SaxonHE10-5J\saxon-he-10.5.jar" -t -it -xsl:compiler\compile-xslt-tests.xsl
Saxon-HE 10.5J from Saxonica
Java version 1.8.0_292
URIResolver.resolve href="xslt/main.xsl" base="file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/resolve-uri-test/compiler/compile-xslt-tests.xsl"
Stylesheet compilation time: 676.063ms
Processing  (no source document) initial template = xsl:initial-template
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="3"
                exclude-result-prefixes="#all">
   <xsl:include href="file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/resolve-uri-test/common/runtime-utils.xsl"/>
</xsl:stylesheet>

while running Saxon HE or EE Java against compile-xslt-tests-HE.xsl.sef gives

C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\resolve-uri-test>java -jar "C:\Program Files\Saxonica\SaxonHE10-5J\saxon-he-10.5.jar" -t -it -xsl:compiler\compile-xslt-tests-HE.xsl.sef
Saxon-HE 10.5J from Saxonica
Java version 1.8.0_292
Stylesheet compilation time: 515.0315ms
Processing  (no source document) initial template = xsl:initial-template
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="3"
                exclude-result-prefixes="#all">
   <xsl:include href="file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/common/runtime-utils.xsl"/>
</xsl:stylesheet>

So the difference is in the constructed xsl:include/@href URIs:

file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/resolve-uri-test/common/runtime-utils.xsl
vs.
file:/C:/Users/marti/OneDrive/Documents/xslt/blog-xslt-3-by-example/common/runtime-utils.xsl

What should be the base URI for resolve-uri called in an included module, the one of the included file or the one of the including file?


Replies (5)

Please register to reply

RE: resolve-uri differences between .xsl and compiled .sef - Added by Martin Honnen over 2 years ago

Thinking further about this, I think it boils down to the question whether a compiled version of a main stylesheet module that includes or import other modules is supposed to preserve the differences in the static base URIs that the modules can have.

It seems that Saxon doesn't do that in its SEF format, a template from an imported module that has a different base URI than the importing module as long as XSLT files are used, will inside of the SEF simply have the URI of the SEF as the static base URI.

Any thoughts?

I don't know of another processor with an export format to compare.

RE: resolve-uri differences between .xsl and compiled .sef - Added by Michael Kay over 2 years ago

Sorry, I haven't had time to look into the detail yet, but to help you with your thinking on this, the general idea is that a SEF file can optionally be relocatable. If it's not relocatable, then the static base URI of any instruction in the stylesheet (if required at run time) is supposed to be the same as the source location (which can vary across the stylesheet). If it is relocatable, then the static base URI is taken as the deployment location of the SEF file (which of course is consistent across the stylesheet).

RE: resolve-uri differences between .xsl and compiled .sef - Added by Martin Honnen over 2 years ago

Ah, yes, that seems to explain it. Does xslt3 of Saxon-JS 2 only have the option relocate:on or relocate:true? When I use it to compile/export a stylesheet it says something like "SEF generated by Saxon-JS 2.3 [...] with -target:JS -relocate:true" but any attempt to call it with -relocate:off or -relocate:false gives "Command line option -relocate is not recognized".

As the whole attempt to test SEF export and use on the Java side originated from my failed attempt to have Saxon-JS compile a stylesheet making use of resolve-uri in an included module I guess that's where I went wrong, trying to use -relocate:on on the Java side as well.

RE: resolve-uri differences between .xsl and compiled .sef - Added by Michael Kay over 2 years ago

Yes, I strongly suspect the XX compiler forces relocate:on. I found some commented out code suggesting an abandoned attempt to implement relocate:off. I'd need to look at it more carefully to be 100% sure of this.

RE: resolve-uri differences between .xsl and compiled .sef - Added by Norm Tovey-Walsh over 2 years ago

Saxonica Developer Community writes:

Yes, I strongly suspect the XX compiler forces relocate:on. I found
some commented out code suggesting an abandoned attempt to implement
relocate:off. I'd need to look at it more carefully to be 100% sure of
this.

That’s consistent with what I’ve observed in the way options are passed
to it during building and testing. I made a note to look into it, but
it’s on page two or three of my todo list. :-)

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

    (1-5/5)

    Please register to reply