RE: [xsl] XTTE0570 at compilation, depending on runtime conditions?

Subject: RE: [xsl] XTTE0570 at compilation, depending on runtime conditions?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 4 Nov 2007 21:58:27 -0000
>   Is it legal for an XSLT 2.0 processor provided the following input:
> 
>     <xsl:variable name="v" as="xs:integer">
>       <xsl:choose>
>         <xsl:when test="$p/@a">1</xsl:when>
>         <xsl:when test="$p/@b">2</xsl:when>
>       </xsl:choose>
>     </xsl:variable>
> 
> to give a compilation error with code XTTE0570?  That is, 
> arguing that if none of the conditions succeed, then the 
> empty sequence would be set as the value of $v, but this is 
> not permited per the @as.  Please note I say a *compilation* 
> error, not even trying to execute the stylesheet.

I hit this with one or two test cases in Saxon 9.0, and thought hard about
whether I should raise this error or not. Basically the rule with type
errors such as XTTE0570 is that you are allowed to raise a type error at
compile time if there is an expression which, if executed, would always
fail. In this case there's an implicit <xsl:otherwise><xsl:sequence
select="()"/></xsl:otherwise> which, if executed, would always fail. It
would certainly be legitimate to raise the error if you wrote that
explicitly, so in my view it's also legitimate if you do it implicitly. This
is probably stricter than most XSLT users are accustomed to, but it's
consistent with what languages like Java do. I'm pretty confident that it's
allowed behaviour - whether it's desirable is an open question.

You can get rid of the error by adding an
<xsl:otherwise><xsl:message/></xsl:otherwise>.

Michael Kay
http://www.saxonica.com/

Current Thread