Re: [xsl] Why does my XSLT produce a Warning message with never-executed code that divides a blank by 10?

Subject: Re: [xsl] Why does my XSLT produce a Warning message with never-executed code that divides a blank by 10?
From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 31 Mar 2024 08:43:13 -0000
On Sun, 2024-03-31 at 07:57 +0000, Roger L Costello costello@xxxxxxxxx
wrote:
>
> How can the XSLT code be written so that, when executed, it doesn't
> produce a Warning message?B 

You may find that reversing the sense of the test gts rid of the
warning -

if (normalize-space($test) ne '')
then xs:integer($test) div 10
else ()

The XPath spec says that dynamic errors must not be raised from the
if/else branch not taken. This is a warning, not an error, but since
the spec explicitly allows this use of if/else, it seems like an
inappropriate warning to me. But it's a judgement call.

A better way to write this, though, might be

if (normalize-space($text) castable as xs:integer)
then xs:intefer(normalize-space($test)) div 10
else ()

liam


--
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