Bug #5307
closedSENR0001 Cannot serialize a map using this output method
100%
Description
Reported by user here: https://saxonica.plan.io/boards/4/topics/8524
The get_result_documents() is currently restricted to PyXdmNode objects. If user sets the raw result values flag then the following error occurs as a result of executing their stylesheet:
Error at char 6 in expression in xsl:sequence/@select on line 21 column 59
SENR0001 Cannot serialize a map using this output method
In template rule with match="item" on line 18 of
invoked by xsl:apply-templates at #14
In template rule with match="root" on line 12 of
invoked by built-in template rule (shallow-copy)
In template rule with match="/" on line 25 of
{'item-1.json': }
The API needs to accept a Map of (String, PyXdmValue).
Updated by O'Neil Delpratt over 2 years ago
- Status changed from New to In Progress
Updated by O'Neil Delpratt over 2 years ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
Bug fixed by adding the option to set the rawResults flag (setCaptureResultDocuments(bool flag, bool rawResults)
). The getResultDocuments now returns a Map of string and Xdmvalue pairs. If the raw result flag has been set true the the map values accepts a sequence output directly as XdmValue without constructing an XML tree, and without serialization.
Updated by O'Neil Delpratt over 2 years ago
Example python code for this feature:
def testResultDocumentWitJson(saxonproc):
inputDoc = saxonproc.parse_xml(xml_text="<a>b</a>")
assert inputDoc is not None
xsl = "<xsl:stylesheet version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='a'>
<xsl:result-document href='result-1.json' method='json'><xsl:sequence select='map { \"value\" : \"foo\" }'/></xsl:result-document></xsl:template></xsl:stylesheet>"
trans = saxonproc.new_xslt30_processor()
executable = trans.compile_stylesheet(stylesheet_text=xsl)
assert executable is not None
executable.set_capture_result_documents(True, True)
executable.set_initial_match_selection(xdm_value=inputDoc)
executable.apply_templates_returning_value()
rdocs_map = executable.get_result_documents()
assert rdocs_map is not None
assert len(rdocs_map) == 1
keysList = [*rdocs_map.keys()]
assert keysList[0].endswith('result-1.json')
assert isinstance(rdocs_map[keysList[0]].head, PyXdmMap)
Updated by O'Neil Delpratt over 2 years ago
- Status changed from Resolved to Closed
- Fixed in version set to 11.3
Bug fix applied in the SaxonC 11.3 maintenance release.
Please register to edit this issue