https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2022-05-07T11:45:42ZSaxonica Developer CommunitySaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=204882022-05-07T11:45:42ZMartin Honnenmartin.honnen@gmx.de
<ul></ul><p>Just to understand, where did you update from, from 11.2 to 11.3? Or some earlier version?</p>
<p>Also, is the problem occurring when running the command line tool <code>transfom</code>/<code>transform.exe</code> or when you write your own code (in what language, using which API)?</p>
<p>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. <a href="https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXsltExecutable-set_base_output_uri" class="external">https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXsltExecutable-set_base_output_uri</a>, <a href="https://www.saxonica.com/saxon-c/doc11/html/classXsltExecutable.html#abd5af13644ffedaa3c1baa3a380eb563" class="external">https://www.saxonica.com/saxon-c/doc11/html/classXsltExecutable.html#abd5af13644ffedaa3c1baa3a380eb563</a> to have relative result document URIs working.</p>
<p>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.</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=204892022-05-07T11:49:59ZMartin Honnenmartin.honnen@gmx.de
<ul></ul><p>Another option to approach the problem from the XSLT side is to use e.g. <code><xsl:result-document href="{resolve-uri('output.xml', static-base-uri())}"></code> instead of <code><xsl:result-document href="output.xml"></code>, that way you don't need to change the PHP or C++ or Python code.</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=204902022-05-07T14:35:07ZMichael Kaymike@saxonica.com
<ul></ul><p>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 <code>Xslt30Processor::setBaseOutputURI()</code> for achieving this.</p>
<p>This should defaults to the directory containing the principal output file, if there is one.</p>
<p>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.</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=204912022-05-07T14:52:22ZLou Burnard
<ul></ul><p>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.</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=204922022-05-07T15:06:08ZO'Neil Delprattoneil@saxonica.com
<ul></ul><p>Hi,</p>
<p>Please see the following page on the API changes: <a href="https://www.saxonica.com/saxon-c/documentation11/index.html#!changes" class="external">https://www.saxonica.com/saxon-c/documentation11/index.html#!changes</a></p>
<p>The <code>set_initial_match_selection</code> method is on the <code>PyXsltExecutable</code> class. You first have to compile a stylesheet using <code>PyXslt30Processor</code> class.</p>
<p>The <code>XsltExecutable</code> class has been introduced across all APIs (C++, Python and PHP) to facilitate the execution of compiled stylesheets. This works alongside the <code>Xslt30Processor</code> class which is used to compile stylesheets.</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=205022022-05-09T11:09:05ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>AwaitingInfo</i></li></ul> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208002022-05-22T09:58:50ZLou Burnard
<ul></ul><p>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.</p>
<hr>
<p>From: Saxonica Developer Community<br>
Sent: Monday, May 9, 2022 12:09 PM<br>
Subject: [SaxonC - Bug <a class="issue tracker-1 status-2 priority-2 priority-default closed" title="Bug: xsl:result-document doesn't function properly (Rejected)" href="https://saxonica.plan.io/issues/5476">#5476</a>] (AwaitingInfo) xsl:result-document doesn't function properly</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208012022-05-22T14:56:23ZLou Burnard
<ul></ul><p>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...</p>
<a name="Here-is-my-simple-xslt-file"></a>
<h2 >Here is my simple xslt file:<a href="#Here-is-my-simple-xslt-file" class="wiki-anchor">¶</a></h2>
<pre><code class="xml syntaxhl" data-language="xml"><span class="cp"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="nt"><xsl:stylesheet</span> <span class="na">xmlns:xsl=</span><span class="s">"http://www.w3.org/1999/XSL/Transform"</span>
<span class="na">xmlns:xs=</span><span class="s">"http://www.w3.org/2001/XMLSchema"</span>
<span class="na">exclude-result-prefixes=</span><span class="s">"xs"</span>
<span class="na">version=</span><span class="s">"2.0"</span><span class="nt">></span>
<span class="nt"><xsl:output</span> <span class="na">media-type=</span><span class="s">"text"</span> <span class="na">omit-xml-declaration=</span><span class="s">"yes"</span> <span class="nt">/></span>
<span class="nt"><xsl:template</span> <span class="na">match=</span><span class="s">"/"</span><span class="nt">></span>
<span class="nt"><xsl:variable</span> <span class="na">name=</span><span class="s">"fName"</span><span class="nt">></span>
<span class="nt"><xsl:value-of</span> <span class="na">select=</span><span class="s">"//b/@n"</span><span class="nt">/></span>
<span class="nt"></xsl:variable></span>
<span class="nt"><xsl:result-document</span> <span class="na">href=</span><span class="s">"{resolve-uri($fName, static-base-uri())}"</span><span class="nt">></span>
<span class="nt"><xsl:apply-templates/></span>
<span class="nt"></xsl:result-document></span>
<span class="nt"></xsl:template></span>
<span class="nt"></xsl:stylesheet></span>
</code></pre>
<hr>
<p>Here is my simple test file:</p>
<hr>
<pre><code class="xml syntaxhl" data-language="xml"><span class="cp"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="nt"><test></span>
<span class="nt"><a</span> <span class="na">n=</span><span class="s">"wibble"</span><span class="nt">></span>An element<span class="nt"></a></span>
<span class="nt"><b</span> <span class="na">n=</span><span class="s">"ignoreMe"</span><span class="nt">></span>Another element<span class="nt"></b></span>
<span class="nt"></test></span>
</code></pre>
<hr>
<p>Running this in Oxygen or with command line saxon(Saxon-HE 9.4.0.4J) does what I expect:</p>
<hr>
<p>lou@Thimk:~/Public/ELTeC-data/Scripts$ saxon test.xml test.xsl<br>
(base) lou@Thimk:~/Public/ELTeC-data/Scripts$ more ignoreMe</p>
<h2>An element<br>
Another element</h2>
<p>HOWEVER running the following Python test:</p>
<hr>
<p>import sys<br>
sys.path.append("/usr/lib/Saxon.C.API/python-saxon")</p>
<a name="import-the-SaxonC-library"></a>
<h1 >import the Saxon/C library<a href="#import-the-SaxonC-library" class="wiki-anchor">¶</a></h1>
<p>import saxonc<br>
with saxonc.PySaxonProcessor(license=False) as proc:<br>
print(proc.version)<br>
xsltproc = proc.new_xslt30_processor()</p>
<a name="Default-directory"></a>
<h1 >Default directory<a href="#Default-directory" class="wiki-anchor">¶</a></h1>
<p>baseURI = '/home/lou/Public/ELTeC-data/Scripts'<br>
xsltproc.set_cwd(baseURI)</p>
<a name="initialise-XSLT-30-processor-result"></a>
<h1 >initialise XSLT 3.0 processor result<a href="#initialise-XSLT-30-processor-result" class="wiki-anchor">¶</a></h1>
<a name="apply-stylesheet"></a>
<h1 >apply stylesheet<a href="#apply-stylesheet" class="wiki-anchor">¶</a></h1>
<a name="result-xsltproctransform_to_stringsource_filetestxml-stylesheet_filetestxsl-base_output_uribaseURI-"></a>
<h2 >result = xsltproc.transform_to_string(source_file='test.xml', stylesheet_file='test.xsl', base_output_uri=baseURI )<a href="#result-xsltproctransform_to_stringsource_filetestxml-stylesheet_filetestxsl-base_output_uribaseURI-" class="wiki-anchor">¶</a></h2>
<p>produces</p>
<hr>
<h2>SaxonC-HE 11.3 from Saxonica<br>
source in transformFiletoString=test.xsl stylsheet=test.xsl<br>
Error in xsl:result-document/@href on line 12 column 78 of test.xsl:<br>
XTDE1500 Cannot write to a URI that has already been read:<br>
file:///home/lou/Public/ELTeC-data/Scripts/test.xsl<br>
In template rule with match="/" on line 7 of test.xsl</h2>
<p>I don't care particularly about the typo ("stylsheet"), but why is it<br>
trying to write to the XSLT source file (I assume that that is the URI<br>
which has already been read)?</p>
<hr>
<p>From: Saxonica Developer Community<br>
Sent: Monday, May 9, 2022 12:09 PM<br>
Subject: [SaxonC - Bug <a class="issue tracker-1 status-2 priority-2 priority-default closed" title="Bug: xsl:result-document doesn't function properly (Rejected)" href="https://saxonica.plan.io/issues/5476">#5476</a>] (AwaitingInfo) xsl:result-document doesn't function properly</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208062022-05-23T08:21:27ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>AwaitingInfo</i> to <i>In Progress</i></li><li><strong>Assignee</strong> set to <i>O'Neil Delpratt</i></li><li><strong>Found in version</strong> set to <i>11.3</i></li></ul> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208072022-05-23T08:29:59ZO'Neil Delprattoneil@saxonica.com
<ul></ul><p>H,</p>
<p>Do you have the test.xml please?</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208082022-05-23T08:32:38ZO'Neil Delprattoneil@saxonica.com
<ul></ul><p>I managed to get the sample xml file, by editing your comment. It got rendered in the HTML</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208142022-05-23T09:08:20ZO'Neil Delprattoneil@saxonica.com
<ul></ul><p>I managed to run Saxon-HEC 11.3 on a ubuntu Linux machine with the files you provided and got the expected <code>ignoreMe</code> file with the content:</p>
<pre><code>
An element
Another element
</code></pre>
<p>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.</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208152022-05-23T09:10:09ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>AwaitingInfo</i></li></ul> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208242022-05-23T13:26:14ZLou Burnard
<ul></ul><p>Removing the "base_output_uri=baseURI " from the transform_to_string call made this problem go away. Sorry to waste your time !</p> SaxonC - Bug #5476: xsl:result-document doesn't function properlyhttps://saxonica.plan.io/issues/5476?journal_id=208322022-05-23T15:33:21ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>AwaitingInfo</i> to <i>Rejected</i></li></ul><p>I am closing this bug issue as the problem as been resolved by the user.</p>