 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 15th, 2009, 12:51 PM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cast string as boolean
I am receiving the following parameter:
<xsl:param name="preferencesBean" select="'currentPageNum,1;numOfPages,1;numOfRecord s,0;display,true()"/>
I am then extracting each name,value pair and building a variable for each:
<xsl:variable name="preferenceParameters">
<xsl:variable name="tokenizedValues" select="tokenize($preferencesBean,';')"/>
<xsl:for-each select="$tokenizedValues">
<xsl:if test="(substring-after(.,',') !='') and (substring-after(.,',') != 'null')">
<var>
<xsl:attribute name="name" select="substring-before(.,',')"/>
<xsl:attribute name="value" select="substring-after(.,',')"/>
</var>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="currentPageNum" select="$preferenceParameters/node()[@name eq 'currentPageNum']/@value" as="xs:integer"/>
<xsl:variable name="numOfPages" select="$preferenceParameters/node()[@name eq 'numOfPages']/@value" as="xs:integer"/>
<xsl:variable name="numOfRecords" select="$preferenceParameters/node()[@name eq 'numOfRecords']/@value" as="xs:integer"/>
<xsl:variable name="display" select="$preferenceParameters/node()[@name eq 'display']/@value" as="xs:boolean"/>
Two issues I am having:
1. I think there is a more elegant way to do this?
2. Since the initial parameter value is a string, I am unable to cast it (display,true()) as a boolean.
Any help is greatly appreciated. Thanks!
|
|

June 15th, 2009, 01:07 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
1. I think there is a more elegant way to do this?
Why not use XML to represent your structured string, instead of using a private markup-language?
2. Since the initial parameter value is a string, I am unable to cast it (display,true()) as a boolean.
Why not use the approved lexical representation of values of the data type ("0", "1", "true", "false"), rather than using the form designed for use when values are represented as literals in an XPath expression?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

June 15th, 2009, 01:17 PM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Unfortunately, I am constrained by the existing system. I do have the option to receive the value as 'true', but wouldn't it still be evaluated as a string, which would need to be then cast as a boolean?
I am trying to avoid testing for a string value:
<xsl:if test="$display eq 'true'">
I would prefer:
<xsl:if test="$display eq true()">
|
|

June 15th, 2009, 01:21 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
At least 'true' and 'false' can be cast to an xs:boolean while 'true()' and 'false()' can't be.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

June 15th, 2009, 01:30 PM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks to you both. I didn't realize that 'true' could be cast as a boolean. I was trying true(), which was the problem.
|
|
 |