[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: 'true' or true()

Subject: Re: 'true' or true()
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 01 Nov 2010 21:54:39 +0000
Re:  'true' or true()
On 01/11/2010 21:14, 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.

Thanks,
Karl..

In XSLT 2.0, declare the expected type of the parameter: <xsl:param name="isTrue" select="true()" as="xs:boolean"/>.

The way parameters are passed to a stylesheet depends on the product and API you are using: for example from the Saxon command line you will be able to pass the string values "true", "false", "0", or "1", but the important thing is that whatever is passed, you know you are dealing with a boolean, and not (say) a string.

If you can't do this, then validate the parameter within your code:

<xsl:when test="$isTrue='true'">...
<xsl:when test="$isTrue='false'">...
<xsl:otherwise><xsl:message...

Don't just take the effective boolean value. The EBV of all strings other than "" is true.

Michael Kay
Saxonica

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.