Project

Profile

Help

How the set the base output URI of XSLT 3 in Python API?

Added by Martin Honnen over 4 years ago

The .NET and the Java API of Xslt30Transformer have a property/setter for the base output URI e.g. http://saxonica.com/html/documentation/dotnetdoc/Saxon/Api/Xslt30Transformer.html#BaseOutputURI or http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#setBaseOutputURI-java.lang.String-.

For the Python API I am not sure how to set this, I have tried to use set_cwd with e.g.

xslt30_processor.set_cwd(os.getcwd())

but this doesn't seem to help with a stylesheet called for the name="xsl:initial-template" and xsl:result-document instructions with relative URIs in the href attribute. I get an error

Error in xsl:result-document/@href on line 19 column 94 of sheet.xsl:
  SXRD0002: The system identifier of the principal output file is unknown
at template xsl:initial-template on line 16 of sheet.xsl:
     invoked by xsl:iterate at file:///C:/SomeDir/sheet.xsl#17
at template xsl:initial-template on line 16 of sheet.xsl:
     invoked by unknown caller (null)

The Python code (run against saxonc of HEC 1.2.1) is like this:

import saxonc
import os

with saxonc.PySaxonProcessor() as proc:
    print(proc.version)
    
    xslt30_processor = proc.new_xslt30_processor()
    
    xslt30_processor.set_cwd(os.getcwd())
    
    result = xslt30_processor.call_template_returning_string(stylesheet_file = 'streaming-sheet2.xsl', output_file = 'python-result-sheet2.xml')
    
    print(result)

Replies (3)

Please register to reply

RE: How the set the base output URI of XSLT 3 in Python API? - Added by Martin Honnen over 4 years ago

The problem seems to be specific to call_template_returning_string, with xslt30_processor.call_template_returning_file the above works.

Should call_template_returning_string return the primary result as a string but write any secondary results to files if set_cwd has been used?

RE: How the set the base output URI of XSLT 3 in Python API? - Added by O'Neil Delpratt over 4 years ago

Hi Martin,

Thanks for reporting problem. The setter method for the base output URI is missing from Saxon/C. I have created the following bug issue to keep track of the fix: #4395

The fix will be available in the next release.

RE: How the set the base output URI of XSLT 3 in Python API? - Added by O'Neil Delpratt over 4 years ago

I have made changes to the API to now make it possible to set the base_output_uri either:

xslt30_processor.set_base_output_uri('/path-dir')

or

result = xslt30_processor.call_template_returning_string(stylesheet_file = 'streaming-sheet2.xsl', base_output_uri = '/path-dir')

The keyword argument base_output_uri is available for the other stylesheet execution function.

    (1-3/3)

    Please register to reply