Re: Catching message from xsl:message terminate=yes in function

Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]>
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
OK, understood.

I've raised the issue here:

https://saxonica.plan.io/issues/4621

Michael Kay
Saxonica

> On 29 Jun 2020, at 10:09, AirQuick <[email protected]> wrote:
> 
> Sorry, I should have written the problem more clearly.
> 
> The problem is that $err:value in xsl:catch in the demo stylesheet is empty contrary to the spec:
> 
> https://www.w3.org/TR/xslt-30/#element-catch <https://www.w3.org/TR/xslt-30/#element-catch> 
> > err:value     item()* ...For an error raised by evaluating xsl:message with terminate="yes", or a failing xsl:assert, this is the document node at the root of the tree containing the XML message body.
> 
> $err:value contains the message body, if you remove 'as="xs:integer"' from xsl:function in the demo stylesheet.
> 
> ----- Original message -----
> From: Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected] <mailto:mike-JkSD5nQpfvpWk0Htik3J/[email protected]>>
> To: Mailing list for the SAXON XSLT and XQuery processor <[email protected] <mailto:[email protected]>>
> Subject: Re: [saxon] Catching message from xsl:message terminate=yes in function
> Date: Monday, June 29, 2020 16:34
> 
> I'm not sure why you expect the output you do.
> 
> Firstly, xsl:message with terminate=yes does two things: (a) it outputs a message [more strictly, it instantiates a message emitter and passes the message to it], and (b) it throws an error which normally causes termination. Catching the error can prevent the termination, but it does not prevent the output of the message. Your example shows that the exception has been successfully caught, and the xsl:catch is doing what I would expect it to do.
> 
> Secondly, you are expecting the message to be output in the form of a serialized processing instruction. Saxon does insert this processing instruction into the document passed to a user-supplied message emitter; but the default message emitter ignores it. This mechanism was introduced as a way of supplying the error code to user-defined message emitters that need to know, without changing the default way that messages were output in previous releases.
> 
> Michael Kay
> Saxonica
> 
>> On 29 Jun 2020, at 07:46, AirQuick <[email protected] <mailto:[email protected]>> wrote:
>> 
>> I expected Saxon 10.1 and 9.9.1.7 with the stylesheet below to output
>> 
>> <value><?error-code Q{http://www.w3.org/2005/xqt-errors <http://www.w3.org/2005/xqt-errors>}XTMM9000?>my error message</value>
>> 
>> but the actual output is
>> 
>> $ java -jar SaxonHE10-1J/saxon-he-10.1.jar -it -xsl:test.xsl
>> my error message
>> <?xml version="1.0" encoding="UTF-8"?>
>> <err>
>>   <code>err:XTMM9000</code>
>>   <description>Processing terminated by xsl:message at line 28 in test.xsl. Found while atomizing the result of a call to my:test#0</description>
>>   <value/>
>> </err>
>> 
>> 
>> Stylesheet:
>> 
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsl:stylesheet exclude-result-prefixes="#all" version="3.0"
>>   xmlns:err="http://www.w3.org/2005/xqt-errors <http://www.w3.org/2005/xqt-errors>" xmlns:my="my"
>>   xmlns:xs="http://www.w3.org/2001/XMLSchema <http://www.w3.org/2001/XMLSchema>" xmlns:xsl="http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform>">
>> 
>>   <xsl:output indent="yes" />
>> 
>>   <xsl:template name="xsl:initial-template">
>>      <xsl:try>
>>         <xsl:sequence select="my:test()" />
>>         <xsl:catch>
>>            <err>
>>               <code>
>>                  <xsl:value-of select="$err:code" />
>>               </code>
>>               <description>
>>                  <xsl:value-of select="$err:description" />
>>               </description>
>>               <value>
>>                  <xsl:sequence select="$err:value" />
>>               </value>
>>            </err>
>>         </xsl:catch>
>>      </xsl:try>
>>   </xsl:template>
>> 
>>   <xsl:function as="xs:integer" name="my:test">
>>      <xsl:message select="'my error message'" terminate="yes" />
>>      <xsl:sequence select="1" />
>>   </xsl:function>
>> 
>> </xsl:stylesheet>
>> 
>> 
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/ <http://saxon.markmail.org/>
>> [email protected] <mailto:[email protected]>
>> https://lists.sourceforge.net/lists/listinfo/saxon-help <https://lists.sourceforge.net/lists/listinfo/saxon-help> 
> 
> 
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/ <http://saxon.markmail.org/>
> [email protected] <mailto:[email protected]>
> https://lists.sourceforge.net/lists/listinfo/saxon-help <https://lists.sourceforge.net/lists/listinfo/saxon-help> 
> 
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/ <http://saxon.markmail.org/>
> [email protected] <mailto:[email protected]>
> https://lists.sourceforge.net/lists/listinfo/saxon-help <https://lists.sourceforge.net/lists/listinfo/saxon-help>

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.