Project

Profile

Help

Bug #5476

closed

xsl:result-document doesn't function properly

Added by Lou Burnard about 2 years ago. Updated about 2 years ago.

Status:
Rejected
Priority:
Normal
Category:
-
Start date:
2022-05-06
Due date:
% Done:

0%

Estimated time:
Found in version:
11.3
Fixed in version:
Platforms:

Description

I upgraded to SaxonC-HE 11.3 and several things stopped working. One I have not yet found a workround for is a stylesheet which calls xsl:result-document, supplying a bare filename as the value for @href. The intention is to create this file in the current directory (obvs) but the context for that to be done seems to be missing. If the filename supplied does NOT already exist I get diagnostics like this:

Error in xsl:result-document/@href on line 72 column 58 of reporter.xsl: SXRD0002 The system identifier of the principal output file is unknown In template rule with match="/" on line 31 of reporter.xsl None Error in file(file, "rt", encoding = fileEncoding) : cannot open the connection Calls: read.table -> file In addition: Warning message: In file(file, "rt", encoding = fileEncoding) : cannot open file 'metadata.csv': No such file or directory Execution halted

but if the file DOES exist (and should therefore be over-written) all I get is

Error in xsl:result-document/@href on line 72 column 58 of reporter.xsl: SXRD0002 The system identifier of the principal output file is unknown

Either way, this is not what should be happening.

Actions #1

Updated by Martin Honnen about 2 years ago

Just to understand, where did you update from, from 11.2 to 11.3? Or some earlier version?

Also, is the problem occurring when running the command line tool transfom/transform.exe or when you write your own code (in what language, using which API)?

I think the consensus of the Saxonica guys for the API use is that you have to make sure you set the base output URI e.g. https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXsltExecutable-set_base_output_uri, https://www.saxonica.com/saxon-c/doc11/html/classXsltExecutable.html#abd5af13644ffedaa3c1baa3a380eb563 to have relative result document URIs working.

So if you are using the PHP or Python or C++ API and haven't explicitly set the base output URI then try whether that fixes your problem, at least as a workaround.

Actions #2

Updated by Martin Honnen about 2 years ago

Another option to approach the problem from the XSLT side is to use e.g. <xsl:result-document href="{resolve-uri('output.xml', static-base-uri())}"> instead of <xsl:result-document href="output.xml">, that way you don't need to change the PHP or C++ or Python code.

Actions #3

Updated by Michael Kay about 2 years ago

You say "the intention is to create the file in the current directory". In that case you need to ensure that the "base output URI" is the URI of the current directory. There is a method Xslt30Processor::setBaseOutputURI() for achieving this.

This should defaults to the directory containing the principal output file, if there is one.

I think it's right that we're careful about this: writing files to an unintended location, especially when it overwrites an existing file at that location, is a dangerous thing to do, so it makes sense to ask the user to be very explicit about it.

Actions #4

Updated by Lou Burnard about 2 years ago

Thanks for the helpful comments and suggestions.But since you ask, I must have been using a VERY old version of the python API before, because many of the method names seem to have changed or disappeared(e.g. there was something called xsltproc.set_initial_match_selection(file_name=DRIVERFILE) which there no longer is). . But in any case, explicitly setting the base URI seems the best solution: I would like to be able to use my XSL scripts via any interface not just the python one. I'll get back to you if this is still a problem! (I was confused because the stylesheet works as intended when invoked from command line saxon but failed when using the python api.

Actions #5

Updated by O'Neil Delpratt about 2 years ago

Hi,

Please see the following page on the API changes: https://www.saxonica.com/saxon-c/documentation11/index.html#!changes

The set_initial_match_selection method is on the PyXsltExecutable class. You first have to compile a stylesheet using PyXslt30Processor class.

The XsltExecutable class has been introduced across all APIs (C++, Python and PHP) to facilitate the execution of compiled stylesheets. This works alongside the Xslt30Processor class which is used to compile stylesheets.

Actions #6

Updated by O'Neil Delpratt about 2 years ago

  • Status changed from New to AwaitingInfo
Actions #7

Updated by Lou Burnard about 2 years ago

I am no longer getting that error message, so this can be closed. I am still having problems with a stylesheet that tries to set the output URI on the basis of data in the source file though. I will try to simplify the problem and raise as another issue.


From: Saxonica Developer Community
Sent: Monday, May 9, 2022 12:09 PM
Subject: [SaxonC - Bug #5476] (AwaitingInfo) xsl:result-document doesn't function properly

Actions #8

Updated by Lou Burnard about 2 years ago

I am still very puzzled about how to set the result document URI from within an XSLT script using the python wrapper for saxon. So I tried to simplify the issue, and would much appreciate any explanation you can provide...

Here is my simple xslt file:

<?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="xs"  
version="2.0">  
<xsl:output media-type="text"  omit-xml-declaration="yes" />  
<xsl:template match="/">  
<xsl:variable name="fName">  
<xsl:value-of select="//b/@n"/>  
</xsl:variable>  
<xsl:result-document href="{resolve-uri($fName, static-base-uri())}">  
<xsl:apply-templates/>  
</xsl:result-document>  
</xsl:template>  
</xsl:stylesheet> 

Here is my simple test file:


<?xml version="1.0" encoding="UTF-8"?>  
<test>  
<a n="wibble">An element</a>  
<b n="ignoreMe">Another element</b>  
</test> 

Running this in Oxygen or with command line saxon(Saxon-HE 9.4.0.4J) does what I expect:


lou@Thimk:~/Public/ELTeC-data/Scripts$ saxon test.xml test.xsl
(base) lou@Thimk:~/Public/ELTeC-data/Scripts$ more ignoreMe

An element
Another element

HOWEVER running the following Python test:


import sys
sys.path.append("/usr/lib/Saxon.C.API/python-saxon")

import the Saxon/C library

import saxonc
with saxonc.PySaxonProcessor(license=False) as proc:
print(proc.version)
xsltproc = proc.new_xslt30_processor()

Default directory

baseURI = '/home/lou/Public/ELTeC-data/Scripts'
xsltproc.set_cwd(baseURI)

initialise XSLT 3.0 processor result

apply stylesheet

result = xsltproc.transform_to_string(source_file='test.xml', stylesheet_file='test.xsl', base_output_uri=baseURI )

produces


SaxonC-HE 11.3 from Saxonica
source in transformFiletoString=test.xsl stylsheet=test.xsl
Error in xsl:result-document/@href on line 12 column 78 of test.xsl:
XTDE1500 Cannot write to a URI that has already been read:
file:///home/lou/Public/ELTeC-data/Scripts/test.xsl
In template rule with match="/" on line 7 of test.xsl

I don't care particularly about the typo ("stylsheet"), but why is it
trying to write to the XSLT source file (I assume that that is the URI
which has already been read)?


From: Saxonica Developer Community
Sent: Monday, May 9, 2022 12:09 PM
Subject: [SaxonC - Bug #5476] (AwaitingInfo) xsl:result-document doesn't function properly

Actions #9

Updated by O'Neil Delpratt about 2 years ago

  • Status changed from AwaitingInfo to In Progress
  • Assignee set to O'Neil Delpratt
  • Found in version set to 11.3
Actions #10

Updated by O'Neil Delpratt about 2 years ago

H,

Do you have the test.xml please?

Actions #11

Updated by O'Neil Delpratt about 2 years ago

I managed to get the sample xml file, by editing your comment. It got rendered in the HTML

Actions #12

Updated by O'Neil Delpratt about 2 years ago

I managed to run Saxon-HEC 11.3 on a ubuntu Linux machine with the files you provided and got the expected ignoreMe file with the content:

  
An element  
Another element

Is it possible you can provide more information on the environment you are running the python script in, please? Also, check that you have no old version of SaxonC on your system alongside the new library.

Actions #13

Updated by O'Neil Delpratt about 2 years ago

  • Status changed from In Progress to AwaitingInfo
Actions #14

Updated by Lou Burnard about 2 years ago

Removing the "base_output_uri=baseURI " from the transform_to_string call made this problem go away. Sorry to waste your time !

Actions #15

Updated by O'Neil Delpratt about 2 years ago

  • Status changed from AwaitingInfo to Rejected

I am closing this bug issue as the problem as been resolved by the user.

Please register to edit this issue

Also available in: Atom PDF