xsl-list
[Top] [All Lists]

Re: [xsl] Defensive programming in XSLT using asserts and as="..."

2022-05-06 14:25:49
On Fri, 2022-05-06 at 16:27 +0000, Michael Kay mike(_at_)saxonica(_dot_)com 
wrote:
If you can express the condition with an @as attribute, use that in
preference to an xsl:assert, because it's much more amenable to
static analysis 

This is a good reason; another is that programming errors in assert
expressions are much less likely to be caught than mistakes in as=

For example,

<xsl:param name="item" as="element(author)"/>

is equivalent to:

<xsl:param name="item"/>
<xsl:assert test="name($item) eq 'author'"/>

except of course, as Mike Kay pointed out, it isn't - not only for the
reasons he gave, but also because when you use as="element(author)",
every single use of that parameter will be tested automatically, so
<xsl:sequence select="$item + 6" />
can raise a static error.


-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>