Help on XQuery element constructor using an enclosed expression evaluating to an array
Added by Martin Honnen about 8 years ago
When I have an XQuery 3.1 query of the form
xquery version "3.1";
{[1, 2, 3]}
and run it with Saxon 9.7.0.8J from the command line I get an error "Cannot serialize an array using the xml method".
However, https://www.w3.org/TR/xquery-31/#id-content says
Enclosed expressions are evaluated as follows:
Each array returned by the enclosed expression is flattened by calling the function array:flatten() before the steps that follow.
As @array:flatten@ (https://www.w3.org/TR/xpath-functions-31/#func-array-flatten) "Replaces any array appearing in a supplied sequence with the members of the array", I think the content of the @data@ element should not be an array but rather a text node with @1 2 3@.
So why does Saxon give me the error "Cannot serialize an array using the xml method"?
When I change output method to @adaptive@, the query works, but I don't understand why the output method @xml@ is preventing the code I have from working.
Replies (3)
Please register to reply
RE: Help on XQuery element constructor using an enclosed expression evaluating to an array - Added by Martin Honnen about 8 years ago
It seems the XSLT implementation suffers from the same problem, the stylesheet
gives an error
java.lang.UnsupportedOperationException: An array does not have a string value at net.sf.saxon.ma.arrays.SimpleArrayItem.getStringValueCS(SimpleArrayItem.java:334) at net.sf.saxon.serialize.UncommittedSerializer.append(UncommittedSerializer.java:219) at net.sf.saxon.event.ProxyReceiver.append(ProxyReceiver.java:233) at net.sf.saxon.event.ProxyReceiver.append(ProxyReceiver.java:233) at net.sf.saxon.event.SequenceReceiver.append(SequenceReceiver.java:124) at net.sf.saxon.event.ComplexContentOutputter.append(ComplexContentOutputter.java:589) at net.sf.saxon.event.SequenceReceiver.append(SequenceReceiver.java:124) at EE_xsl_initial_template_01613095350.process(file:/SomePath/test2016090205.xsl:10) at com.saxonica.ee.bytecode.CompiledExpression.process(CompiledExpression.java:70) at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:258) at net.sf.saxon.Controller.callTemplate(Controller.java:2406) at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:707) at net.sf.saxon.Transform.processFile(Transform.java:1232) at net.sf.saxon.Transform.doTransform(Transform.java:795) at net.sf.saxon.Transform.main(Transform.java:77)
although the spec https://www.w3.org/XML/Group/qtspecs/specifications/xslt-30/html/#constructing-complex-content says
Any array item in the sequence (see 27.7.1 Arrays) is replaced by its members, recursively. This is equivalent to applying the array:flattenFO31 function defined in [Functions and Operators 3.1].
When I use @output method="adaptive"@ the error goes away.
RE: Help on XQuery element constructor using an enclosed expression evaluating to an array - Added by Michael Kay about 8 years ago
I can confirm that this rule in the XQuery and XSLT specifications has not yet been implemented in Saxon.
Though I'm a little surprised, because there are QT3 test cases (in the misnamed prod-ArrayTest test set) and we are passing them.
Please register to reply