[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT 3.0 try/catch doubts

Subject: 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
 XSLT 3.0 try/catch doubts
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.