This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Boolean true() and false() as strings?


> A curious thing (well, to me!)... consider this template rule:

The <xsl:value-of> converts the booleans to strings; and the use of
xsl:variable with content creates a result tree fragment containing this
string as a child node. So you are quite right, test="$units_gt_300" would
always succeed, because it is testing whether the node-set equivalent to the
RTF contains any nodes: converting an RTF to a boolean always returns true
(despite what my book says on page 81 [sorry!].

But why don't you just write
<xsl:variable name="units_gt_300" select="units &gt; 300"/>
That way you get a variable whose type is boolean.
Mike Kay

> 
> <xsl:template match="sales">
>    <h2>Regions Selling More than 300 Units:</h2>
>    <xsl:for-each select="region">
>      <xsl:variable name="units_gt_300">
>        <xsl:choose>
>          <xsl:when test="number(units) &gt; 300">
>            <xsl:value-of select="true()"/>
>          </xsl:when>
>          <xsl:otherwise>
>            <xsl:value-of select="false()"/>
>          </xsl:otherwise>
>        </xsl:choose>
>      </xsl:variable>
>      <xsl:if test="$units_gt_300='true'">
>        <h3><xsl:value-of select="concat(@name, ' (', units, ' 
> units)')"/></h3>
>      </xsl:if>
>    </xsl:for-each>
> </xsl:template>
> 
> Note the assignment of Boolean true() or false() to the 
> variable, and the 
> <xsl:if> test. Why can't the latter be simply:
> 
>    <xsl:if test="$units_gt_300">
> 
> i.e., why the need to test vs. the string value "true"? 
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]