Re: [xsl] xslt 3.0, and use of 'as' attribute with xsl:variable

Subject: Re: [xsl] xslt 3.0, and use of 'as' attribute with xsl:variable
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 31 Aug 2023 16:35:12 -0000
> I think, the XSLT 3.0 variable declaration, <xsl:variable name="var1"
select="'4'" as="xs:integer"/> should work similarly (I think, it should
succeed, and the specific XPath 3.1 function conversion rule seems to me is
wrong if it, disallows this. Apologies to be saying like this, and disagreeing
to the XPath 3.1 spec wrt this point) to what "cast as" expressions as cited
above are able to do.
>
> Any thoughts please?
>

With implicit conversion there is a balance between the early error detection
that you get from strict rules, versus the convenience you get from lax rules.
For 4.0 we have relaxed the rules a little, for example <xsl:variable
select="2" as="xs:positiveInteger"/> will now work.

Note that in XQuery (prior to 4.0), you don't even get atomization in a
variable binding, for example

let $x as xs:string := <a>help</a>

will give you a type error.

To understand these decisions you need a historical and sociological
perspective as well as a purely technical one. XPath 1.0 was completely
dynamically typed, in the tradition of Javascript, while XQuery 1.0 was
designed by people from the database query languages tradition where
optimization is a key driver, and optimization often relies on having accurate
knowledge of static types. So there were some real clashes, and as a result
you get some messy design compromises.

Michael Kay
Saxonica

Current Thread