Trapping <xsl:message>?

53 views
Skip to first unread message

David Birnbaum

unread,
Jun 27, 2020, 6:12:07 PM6/27/20
to XSpec
Is it possible for a test to trap <xsl:message terminate="yes">? I am able to trap error(), so the functionality is available in a different way, but I do not find any documentation at https://github.com/xspec/xspec/wiki/Writing-Scenarios#testing-dynamic-errors about how to trap an <xsl:message> that is supposed to terminate a transformation.

AirQuick

unread,
Jun 28, 2020, 12:47:22 AM6/28/20
to xspec...@googlegroups.com
Yes, you can test <xsl:message terminate="yes">. I added some description to https://github.com/xspec/xspec/wiki/Writing-Scenarios#testing-dynamic-errors . Hope it helps.
--
You received this message because you are subscribed to the Google Groups "XSpec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.

David Birnbaum

unread,
Jun 28, 2020, 3:24:49 PM6/28/20
to XSpec
Hmm ... my XSLT function contains:

<xsl:if test="$f:window-size mod 2 eq 0 or $f:window-size lt 3">
 
<xsl:message terminate="yes" select="concat('Invalid window size: ', $f:window-size, '; window size must be odd integer greater than 3')" />
</xsl:if>


$x:result?err returns:

<pseudo-map xmlns:djb="http://www.obdurodon.org"
           
xmlns:f="http://www.obdurodon.org/function-variables">map{"column-number":19,"line-number":126,"module":"file:/Users/djb/repos/plot/lib/plot-lib.xsl","code":Q{http://www.w3.org/2005/xqt-errors}XTMM9000,"value":(),"description":"Processing terminated by xsl:message at line 126 in plot-lib.xsl. Found while atomizing the result of a call to djb:get-weights-scale#3"}</pseudo-map>


$x:result?err?value/text(), then, returns only ().

On Sunday, June 28, 2020 at 12:47:22 AM UTC-4, AirQuick wrote:
Yes, you can test <xsl:message terminate="yes">. I added some description to https://github.com/xspec/xspec/wiki/Writing-Scenarios#testing-dynamic-errors . Hope it helps.

----- Original message -----
From: David Birnbaum <djb...@gmail.com>
Subject: Trapping <xsl:message>?
Date: Sunday, June 28, 2020 05:03

Is it possible for a test to trap <xsl:message terminate="yes">? I am able to trap error(), so the functionality is available in a different way, but I do not find any documentation at https://github.com/xspec/xspec/wiki/Writing-Scenarios#testing-dynamic-errors about how to trap an <xsl:message> that is supposed to terminate a transformation.


--
You received this message because you are subscribed to the Google Groups "XSpec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xspec...@googlegroups.com.

AirQuick

unread,
Jun 28, 2020, 3:34:48 PM6/28/20
to xspec...@googlegroups.com
What is your Saxon version?

> Note that Saxon 9.9.1.5 or older has a bug where $x:result?err?value is always empty.
> Use 9.9.1.6 or later, if you need to test your error message body of <xsl:message terminate="yes">.

To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.

David Birnbaum

unread,
Jun 28, 2020, 3:43:57 PM6/28/20
to XSpec
Running Tests...
Testing with SAXON EE 10.0

AirQuick

unread,
Jun 28, 2020, 4:35:22 PM6/28/20
to xspec...@googlegroups.com
Not reproduced on my end using XSpec v1.6.0 and Saxon-EE 10.0. It would be appreciated if you could provide a set of small files to reproduce the same result.

It is likely that Saxon actually ends up returning an empty value in your case.
To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.

David Birnbaum

unread,
Jun 28, 2020, 5:00:08 PM6/28/20
to XSpec
(base) koala-4:lib djb$ cat message-test.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns
:xs="http://www.w3.org/2001/XMLSchema" xmlns:djb="http://www.obdurodon.org"
    xmlns
:f="http://www.obdurodon.org/function-variables"
    xmlns
:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math"
    version
="3.0">
   
<xsl:function name="djb:get-weights-scale" as="xs:double+">
       
<xsl:param name="f:window-size" as="xs:integer"/>

       
<xsl:if test="$f:window-size mod 2 eq 0 or $f:window-size lt 3">
           
<xsl:message terminate="yes"
               
select=
"
                    normalize-space(concat('Invalid window size: ',

                    $f:window-size, '; window size must be odd integer greater than
                3'))"
           
/>
       
</xsl:if>
        <xsl:sequence>1</
xsl:sequence>
   
</xsl:function>
</
xsl:stylesheet>
(base) koala-4:lib djb$ cat message-test.xspec
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" xmlns:djb="http://www.obdurodon.org"
    xmlns
:f="http://www.obdurodon.org/function-variables" stylesheet="message-test.xsl">
   
<x:scenario label="Scenario for testing function get-weights-scale" catch="yes">
       
<x:call function="djb:get-weights-scale">
           
<x:param name="f:window-size" select="4"/>
       
</x:call>
        <x:expect label="err:value"
            test="$x:result?err?value/
text()">Invalid window size: 4; window size must be odd integer greater than 3</x:expect>
    </x:scenario>
</x:description>
(base) koala-4:lib djb$ xspec message-test.xspec
Transformation failed: Unknown configuration feature help
Saxon script not found, invoking JVM directly instead.


Creating Test Stylesheet...





Running Tests...
Testing with SAXON EE 10.0
Scenario for testing function get-weights-scale
Invalid window size: 4; window size must be odd integer greater than 3
err:value
      FAILED


Formatting Report...
passed: 0 / pending: 0 / failed: 1 / total: 1
Report available at ./xspec/message-test-result.html
Done.
(base) koala-4:lib djb$ cat xspec/message-test-result.xml
<?xml version="
1.0" encoding="UTF-8"?>
<x:report xmlns:djb="
http://www.obdurodon.org"
          xmlns
:f="http://www.obdurodon.org/function-variables"
          xmlns
:x="http://www.jenitennison.com/xslt/xspec"
          stylesheet
="file:/Users/djb/repos/plot/lib/message-test.xsl"
          date
="2020-06-28T16:58:12.293-04:00"
          xspec
="file:/Users/djb/repos/plot/lib/message-test.xspec">
   
<x:scenario id="scenario1"
               xspec
="file:/Users/djb/repos/plot/lib/message-test.xspec">
     
<x:label>Scenario for testing function get-weights-scale</x:label>
      <x:call function="djb:get-weights-scale">
         <x:param name="f:window-size" select="4"/
>
     
</x:call>
      <x:result select="/
*">
         <pseudo-map xmlns="
http://www.jenitennison.com/xslt/xspec">map{"err":map{"column-number":15,"line-number":15,"module":"file:/Users/djb/repos/plot/lib/message-test.xsl","code":Q{http://www.w3.org/2005/xqt-errors}XTMM9000,"value":(),"description":"Processing terminated by xsl:message at line 15 in message-test.xsl. Found while atomizing the result of a call to djb:get-weights-scale#1"}}</pseudo-map>
     
</x:result>
      <x:test id="scenario1-expect1" successful="false">
         <x:label>err:value</
x:label>
         
<x:result select="()"/>
         
<x:expect test="$x:result?err?value/text()" select="/text()">Invalid window size: 4; window size must be odd integer greater than 3</x:expect>
      </
x:test>
   
</x:scenario>
</
x:report>
(base) koala-4:lib djb$

AirQuick

unread,
Jun 29, 2020, 3:03:26 AM6/29/20
to xspec...@googlegroups.com
Thanks for the complete set for reproduction.

Looks like xsl:try on the current versions of Saxon fails to transfer the message body from xsl:message[@terminate="yes"] in xsl:function[@as].

To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.

David Birnbaum

unread,
Jun 29, 2020, 1:00:07 PM6/29/20
to XSpec
Thank you for passing this along to Saxonica, where I see that Michael Kay has now opened a bug issue for it. I'll watch for a fix in Saxon, and continue to use error() until that happens.

AirQuick

unread,
Jun 29, 2020, 1:46:28 PM6/29/20
to xspec...@googlegroups.com
In https://github.com/xspec/xspec/pull/1030 , I'm adding an internal test to XSpec. That will ensure that your case will work on XSpec with the next maintenance release of Saxon (presumably 10.2) and onward. Just FYI.
To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.

David Birnbaum

unread,
Jul 1, 2020, 7:39:05 PM7/1/20
to XSpec
Reply all
Reply to author
Forward
0 new messages