[xsl] XSLT 3.0 try/catch doubts

Subject: [xsl] XSLT 3.0 try/catch doubts
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 22 Feb 2019 09:58:04 -0000
Hi all,
    I've been trying to do one of XSLT 3.0 transformation using XSLT 3.0's
try/catch syntax. Below are my examples, and my questions thereafter. I'm
using Saxon EE 9.9 as an XSLT processor.

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<test>
    <hello/>
    <hello/>
    <hello/>
    <hello/>
    <hello/>
</test>

Stylesheet 1:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

                         xmlns:err="http://www.w3.org/2005/xqt-errors";
                         exclude-result-prefixes="err"
                         version="3.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:try>
            <xsl:value-of select="for $x in (1 to count(test/hello)) return
(1 div 0)"/>
    <xsl:catch errors="*">
         <error code="{$err:code}" description="{$err:description}"
location="line:{$err:line-number}, col:{$err:column-number}"/>
     </xsl:catch>
        </xsl:try>
    </xsl:template>

</xsl:stylesheet>

This transformation (Stylesheet 1) with the specified input XML, gives me
following output,

Error evaluating (1 div 0) in xsl:value-of/@select on line 11 column 87 of
foo1.xsl:
  FOAR0001: Integer division by zero
Integer division by zero

Stylesheet 2:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

                         xmlns:err="http://www.w3.org/2005/xqt-errors";
                         exclude-result-prefixes="err"
                         version="3.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:try>
             <xsl:value-of select="for $x in (1 to count(test/hello))
return ($x div 0)"/>
     <xsl:catch errors="*">
         <error code="{$err:code}" description="{$err:description}"
location="line:{$err:line-number}, col:{$err:column-number}"/>
     </xsl:catch>
        </xsl:try>
    </xsl:template>

</xsl:stylesheet>

(the difference of this stylesheet, from the previous one is having $x div
0 instead of 1 div 0 so as to try best not to halt during static analysis
of stylesheet. This I think, forces the XSLT processor to process the input
XML document and do the transformation)

This transformation (Stylesheet 2) with the same specified input XML, gives
me following output,

<?xml version="1.0" encoding="UTF-8"?>
<error code="err:FOAR0001"
          description="Integer division by zero"
          location="line:11, col:43"/>

My questions are,
In the first case (Stylesheet 1), is XSLT processor able to determine from
static analysis of stylesheet that 1 div 0 (which is written in a "for"
expression) is a problem, and the XSLT processor doesn't progress with
actual transformation (i.e reading input XML and transforming it)?

I think, with Stylesheet 2 since the div by 0 expression is written as $x
div 0, the div by 0 error can only be found as a dynamic error.

Needless to mention, I've found XSLT 3.0's try/catch instruction to be
quite useful.

Any thoughts and comments, related to the mentioned points would be great.




-- 
Regards,
Mukul Gandhi

alt address : mukulgandhi@xxxxxxx

Current Thread