Project

Profile

Help

Feature #5213

closed

Ability to specify the output mode of xsl:message

Added by Andy Yar over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2022-01-19
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

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 &amp; 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?

Actions #1

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 &amp;. 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.

Actions #2

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 &amp;. 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 &.

Thanks, I will look into the net.sf.saxon.s9api/MessageListener interface.

Actions #3

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)

Actions #4

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

Also available in: Atom PDF