xsl-list
[Top] [All Lists]

Re: [xsl] 'true' or true()

2010-11-01 16:28:20
At 2010-11-01 14:14 -0700, Karl Stubsjoen wrote:
I have a parameter which will either be, true() by default or 'true'
(set by user).  Given the name isTrue, how do you properly write the
if test below:

<xsl:param name="isTrue" select="true()"/>
<xsl:if test="$isTrue or isTrue=true()">

When user sets the param value = 'false' the above isTrue test still passes.

Right ... because most tools pass user-specified parameter values as strings, and any non-empty string tests as true.

In your situation I would do for XSLT 1.0:

  <xsl:param name="isTrue" select="'true'"/>
  ...
  <xsl:if test="$isTrue='true'">...

If you are using XSLT 2.0 I would cast the passed value using xsd:boolean() which has a value set of four strings '1', '0', 'true' and 'false'.

I hope this helps.

. . . . . . . . Ken


--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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