Re: [xsl] Is there any benefit to creating a variable and specifying as="xs:string"?

Subject: Re: [xsl] Is there any benefit to creating a variable and specifying as="xs:string"?
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 10 Jun 2024 06:16:44 -0000
>> That "as" clause says the ICAO param is a string value. Well, everything is
a string.

Nonsense. Saying as="xs:string" stops the caller from supplying (say) a
boolean, a number, or a map.

>>
>> Bonus question: The value to populate the ICAO param should be a 4-letter,
uppercase value, such as KBOS. Is there anyway to express that
requirement/constraint in the "as" clause?
>

If you have a schema-aware processor, you can define a subtype of xs:string
with the restriction facet <pattern value="[A-Z]{4}"/>, and you can name that
subtype in your `as` clause.

The downside of this is that (in XSLT 3.0) the caller must explicitly cast the
supplied parameter value to this subtype. In the proposed 4.0 specification,
this casting happens implicitly.

Michael Kay
Saxonica

Current Thread