Feature #5213
closedAbility to specify the output mode of xsl:message
0%
Description
Hello, we have arrived to a very specific requirement of emitting a structured data during termination of a XSLT transformation. In other words, we would like to easily parse error output of terminated transformation.
We use classic construction of:
<xsl:message terminate="yes">
As the output we use a text anchor followed with serialized JSON:
<xsl:message terminate="yes">
<xsl:variable name="json">
<fn:map>
<fn:string key="ErrorReport">
<xsl:value-of select="'ERROR'"/>
</fn:string>
<fn:string key="PartnerName">
<xsl:value-of select="'Mac & Cheese'"/>
</fn:string>
</fn:map>
</xsl:variable>
<xsl:sequence select="fn:concat('ERROR REPORT: ', fn:xml-to-json($json))"/>
</xsl:message>
Sadly, this construction can't handle JSON output of XML entities correctly. For example, XML '&' doesn't get transformed to JSON '&'. The xsl:assert behaves similarly.
The spec says the body of those construct is a sequence constructor. Is there a way to treat the output as text?
Updated by Michael Kay over 2 years ago
The spec says that the "message" is an XML document, and in many cases (including this one) it will be an XML document containing a single text node. The text node in this case will contain an &
character, but what happens to it next depends on what you do with the message: if you serialize it as XML (which is the default) then it will be output as &
. If you write your own MessageListener
, then the message is supplied as an XdmNode
, and you could instead take the string value of this node, which would contain an unescaped &
.
I think that changing the message API to deliver the message in a form other than an XML node (for example, as a string) would be rather disruptive and complex.
Saxon 11 introduces the option to supply the message to the application as a Message
object, which gives us more scope for formatting the message in different ways.
Updated by Andy Yar over 2 years ago
Michael Kay wrote:
The spec says that the "message" is an XML document, and in many cases (including this one) it will be an XML document containing a single text node. The text node in this case will contain an
&
character, but what happens to it next depends on what you do with the message: if you serialize it as XML (which is the default) then it will be output as&
. If you write your ownMessageListener
, then the message is supplied as anXdmNode
, and you could instead take the string value of this node, which would contain an unescaped&
.
Thanks, I will look into the net.sf.saxon.s9api/MessageListener
interface.
Updated by Michael Kay about 2 years ago
- Status changed from New to Closed
- Assignee set to Michael Kay
I'm going to close this as I believe that the new MessageHandler
interface in Saxon 11 meets the requirement (and it can mostly be achieved using the older MessageListener2
in Saxon 10)
Updated by Andy Yar about 2 years ago
Sorry, I forgot reporting back.
I was kinda forced to use the Receiver
interface since the requirement was to use the command line interface. As far as I'm concerned, it is not possible to supply a MessageListener2
implementation using just command line parameters.
The issue can be closed.
Please register to edit this issue