Actions
Bug #6437
closedPyXdmValue of size 1 where the item is an XDM array returns that item as a PyXdmFunctionItem and calling get_array_value() on that item gives error AttributeError: 'saxonche.PyXdmArray' object has no attribute 'derivednptr'
Start date:
2024-05-23
Due date:
% Done:
100%
Estimated time:
Applies to branch:
Fix Committed on Branch:
12
Fixed in Maintenance Release:
Found in version:
12.4.2
Fixed in version:
12.5
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:
Description
I am struggling to write some Python code Iusing SaxonCHE 12.4.2) allowing me to process the result of an XPath evaluation that is an XDM array. The evaluate
gives me an PyXdmValue
of size
1, the head
then gives me a PyXdmFunctionItem
, not an array, so I try to call get_array_value()
on that function item but then get an error
File "python_saxon\saxonc.pyx", line 4607, in saxonche.PyXdmItem.get_array_value
AttributeError: 'saxonche.PyXdmArray' object has no attribute 'derivednptr'
Complete code:
from saxonche import PySaxonProcessor
xslt = '''<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all">
<xsl:output method="adaptive"/>
<xsl:template match="/">
<xsl:sequence select="array { order!items!item!@code!xs:integer(.) }"/>
</xsl:template>
</xsl:stylesheet>'''
xml = '''<order id="1021">
<items>
<item code="11">
<quantity>2</quantity>
<price>50</price>
</item>
<item code="21">
<quantity>1</quantity>
<price>250</price>
</item>
<item code="13">
<quantity>4</quantity>
<price>100</price>
</item>
</items>
<status>3</status>
</order>'''
with PySaxonProcessor() as processor:
xpath_processor = processor.new_xpath_processor()
xpath_processor.set_parameter('xslt', processor.make_string_value(xslt))
xpath_processor.set_parameter('xml', processor.make_string_value(xml))
xpath_result = xpath_processor.evaluate('''transform(
map {
'stylesheet-text' : $xslt,
'source-node' : parse-xml($xml),
'delivery-format' : 'raw'
}
)?output''')
print(type(xpath_result))
print(xpath_result.size)
head_item = xpath_result.head
print(type(head_item))
array_result = head_item.get_array_value()
result_list = [item.get_atomic_value() for item in array_result.as_list()]
print(result_list)
Output:
Traceback (most recent call last):
File "C:\Users\marti\PycharmProjects\Xslt1Test1\saxonc12test2.py", line 52, in <module>
array_result = head_item.get_array_value()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python_saxon\saxonc.pyx", line 4607, in saxonche.PyXdmItem.get_array_value
AttributeError: 'saxonche.PyXdmArray' object has no attribute 'derivednptr'
<class 'saxonche.PyXdmValue'>
1
<class 'saxonche.PyXdmFunctionItem'>
I wonder whether I shouldn't get a PyXdmArray
directly or if that is not possible how to get a PyXdmArray from the PyXdmFunctionItem.
Related issues
Please register to edit this issue
Actions