Project

Profile

Help

Bug #6146

closed

relative URI resolution in XQuery vs XSLT when loading (XQuery/XSLT) code from the command line over HTTP(S)

Added by Martin Honnen 10 months ago. Updated 6 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Command Line
Sprint/Milestone:
-
Start date:
2023-07-31
Due date:
% Done:

80%

Estimated time:
Legacy ID:
Applies to branch:
10, 11, 12, trunk
Fix Committed on Branch:
10, 11, 12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

Using SaxonJ HE 12.3, I found that the net.sf.saxon.Transform, when taking the -xsl option as a HTTP(S) URL, resolves relative URIs in the XSLT code relative to the loaded XSLT stylesheet so e.g.

java -cp 'C:\Program Files\Saxonica\SaxonHE12-3J\saxon-he-12.3.jar' net.sf.saxon.Transform -t -it -xsl:https://martin-honnen.github.io/xquery/relative-uri-test1.xsl

gives me an output like

SaxonJ-HE 12.3 from Saxonica
Java version 11.0.19
Stylesheet compilation time: 1.9040145s (1904.0145ms)
Processing  (no source document) initial template = xsl:initial-template
Building tree for https://martin-honnen.github.io/xquery/sample1.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Tree built in 2.0469ms
Tree size: 4 nodes, 15 characters, 0 attributes
<?xml version="1.0" encoding="UTF-8"?>
<results>
   <doc-test>
      <root>This is a test.</root>
   </doc-test>
   <unparsed-text-test>This is a plain text test file.
</unparsed-text-test>
</results>

Now when I use a similar XQuery code, however, Saxon tries to resolve the relative URIs relative to the working directory for the unparsed-text call while saying there is no base URI for doc, it appears:

PS C:\Users\marti> java -cp 'C:\Program Files\Saxonica\SaxonHE12-3J\saxon-he-12.3.jar' net.sf.saxon.Query -t -q:https://martin-honnen.github.io/xquery/relative-uri-test1.xq
SaxonJ-HE 12.3 from Saxonica
Java version 11.0.19
Analyzing query from https://martin-honnen.github.io/xquery/relative-uri-test1.xq
Analysis time: 1765.7914 milliseconds
<?xml version="1.0" encoding="UTF-8"?>
<results>
   <doc-test>Relative URI passed to document() function (sample1.xml); but no base URI is available</doc-test>
   <unparsed-text-test>Cannot read file:/C:/Users/marti/sample1.txt(C:\Users\marti\sample1.txt (Das System kann die angegebene Datei nicht finden))</unparsed-text-test>
</results>

The documentation between calling XSLT and XQuery from the command line seems a bit different, for XSLT it seems to mention the option to load the XSLT as a URI (file or http), for XQuery it is not quite clear but it seems as if if code is loadable over HTTP(S) should then it also should have the base URI set.

Used online files: https://martin-honnen.github.io/xquery/relative-uri-test1.xq, https://martin-honnen.github.io/xquery/relative-uri-test1.xsl

Please register to edit this issue

Also available in: Atom PDF