Re: [xsl] What the default datatype of an stylesheet parameter ?

Subject: Re: [xsl] What the default datatype of an stylesheet parameter ?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Nov 2011 05:05:58 -0500
At 2011-11-25 10:23 +0100, Matthieu Ricaud-Dussarget wrote:
Thank you for your as-always clear explanation Michael.

I work more and more with strong datatype in XSLT2, which make the code stronger, I'll do always declare a datatype pour stylesheet params.. and as I always use Saxon I know how it behaves now.
Really usefull tip for boolean parameters !

After testing this, let me just add that the if the supply parameter cannot be casted to the declared type, saxon raise an error.
I don't know how other xslt processors behaves in regard to this point, and sorry that my question is a bit "implementation dependant".

Have you considered something along the lines of:

<xsl:param name="arg"/>

  <xsl:variable name="arg-used" as="xs:whatever?"
                select="if( $arg castable as xs:whatever )
                        then xs:whatever( $arg ) else ()"/>

.... $arg-used ...

Thank you for your response Ken, but as said Michael my question was about "always supplied parameters".

Yes, please forgive my oversight.

But this make me think about another question : if no parameters is supplied, I'm use to test it againts empty string with
<xsl:if test="$foo=''"/>
and it usually works.
Is an empty sequence equal to an emty string?
(maybe the equal operator tries to cast both part to the same type ?

When the types are not the same, the processor reduces one or both of the sides to a common type. The empty sequence is boolean false, and the empty string is boolean false, so when both are converted to boolean, they are the same.

I hope this helps.

. . . . . . . . . . Ken

Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0
Crane Softwrights Ltd.  
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile:
Legal business disclaimers:

Current Thread