saxonxquery-3.1

Query failed with dynamic error: Cannot serialize a map using this output method


This has to be a noob issue, as I'm just starting with XQuery. I was successfully able to build a simple XQuery for eXist that runs an XSL transform. But I have been unsuccessful in building a similar XQuery for Saxon (9.9.1.5J) that runs an XSL transform.

Working XQuery for eXist:

xquery version "3.0";
transform:transform(doc("sample.xml"), doc("sample.xsl"), ())

Failing XQuery for Saxon:

xquery version "3.1";
transform(map{'source-node': doc('sample.xml'),'stylesheet-node':doc('sample.xsl')})

The error reported by Saxon is:

Query failed with dynamic error: Cannot serialize a map using this output method

I've searched Google and SO for this error, but get nothing. I have tried it with and without the output declaration, and with and without an output declaration in the XSL. I've tried it with fn:transform() and transform(). I put in a declaration for the fn namespace too. The transform works from the Saxon command line and from eXist. So I must be missing something simple about the building of the map for the options to fn:transform().


Solution

  • The result of the fn:transform() function is a map, and it looks like you are running the query in a way where the query result gets serialized using the default XML output method. Trying to serialize a map using the XML output method will fail.

    There are several things you could do, depending what exactly you want to achieve. The simplest fix might be to change the body of the query to

    transform(map{'source-node': doc('sample.xml'),'stylesheet-node':doc('sample.xsl')}) 
       ? output
    

    in which case the result will be the principal result document of the transformation, which is probably what you are most interested in.