setting xslt parameter from python/saxon-c
I am having difficulty setting a parameter in my XSLT stylesheet from Python. At the command line, I would write
$saxon [inputXML] [stylesheet] param=value
to supply a value for the <xsl:param name='param'/> at the start of my stylesheet. Using Saxon/C 1.2.1 running with Saxon-HE 126.96.36.199C I write
FILE="input.XML" SCRIPT="stylesheet.xsl" VALUE="value" x = proc.new_xslt30_processor() x.set_result_as_raw_value(True) x.set_initial_match_selection(file_name=FILE) x.set_parameter(param,VALUE) result = x.apply_templates_returning_string(stylesheet_file=script)
(where the uppercase names are Python variables)
But this doesn't work: I get "nameError: name 'param' is not defined."
I am a beginner here so forgive me if this is obvious! I could not find any examples showing this kind of (fairly common) usage in https://www.saxonica.com/saxon-c/doc/html/saxonc.html
#2 Updated by Lou Burnard 3 months ago
I did indeed forget the quotes..
now produces a Saxon error message in line with your comment ("TypeError: Argument 'value' has incorrect type (expected saxonc.PyXdmValue, got str) "
which is fair enough, but how do I tell Python to convert my string to a PyXdmValue?_
#6 Updated by O'Neil Delpratt 3 months ago
Agreed. Thanks for your suggestion. You can find examples in the download
See more details here: https://www.saxonica.com/saxon-c/documentation/index.html#!samples/samples_python
Please register to edit this issue