Subject: Re: [xsl] Defensive programming in XSLT using asserts and as="..." From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 6 May 2022 19:25:45 -0000 |
On Fri, 2022-05-06 at 16:27 +0000, Michael Kay mike@xxxxxxxxxxxx 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 analysisB 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,B 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: B http://www.fromoldbooks.org
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Defensive programming in , Michael Kay mike@xxx | Thread | Re: [xsl] Defensive programming in , Dimitre Novatchev dn |
Re: [xsl] Best Practice: use @as wh, John Lumley john@xxx | Date | [xsl] Initial whitespace in PI from, Bauman, Syd s.bauman |
Month |