Converting to boolean values

page 58 xsl:if test=false Another trick example; this test attribute is always true . As before, we used single quotes inside double quotes to specify that this is a literal string. Because the string has a length greater than zero, the test attribute is always true . The value of the nonempty string, confusing as it is, doesnt matter. xsl:if test=not3 This test attribute is always false . The literal 3 evaluates to true , so its negation is false . On the other hand, the expressions not0 and not-0 are always true . xsl:if test=false This test attribute is always false . The boolean function false always returns the boolean value false . xsl:if test=sectionsection The XPath expression sectionsection returns a node-set. If the current context contains one or more section elements that contain a section element in turn, the test attribute is true . If no such elements exist in the current context, the test attribute is false .

4.2.2 The xsl:choose Element

The xsl:choose element is the equivalent of a case or switch statement in other programming languages. You can also use it to implement an if-then-else statement. An xsl:choose contains at least one xsl:when element logically equivalent to an xsl:if element, with an optional xsl:otherwise element. The test attribute of each xsl:when element is evaluated until the XSLT processor finds one that evaluates to true . When that happens, the contents of that xsl:when element are evaluated. If none of the xsl:when elements have a test that is true , the contents of the xsl:otherwise element if there is one are processed. Heres how these XSLT elements compare to the switch or selectcase statements you might know from other languages: • The C, C++, and Java switch statement is roughly equivalent to the xsl:choose element. The one exception is that procedural languages tend to use fallthrough processing. In other words, if a branch of the switch statement evaluates to true, the runtime executes everything until it encounters a break statement, even if some of that code is part of other branches. The xsl:choose element doesnt work that way. If a given xsl:when evaluates to true, only the statements inside that xsl:when are evaluated. • The Java case statement is equivalent to the xsl:when element. In Java, if a given case statement does not end with a break statement, the following case is executed as well. Again, this is not the case with XSLT; only the contents of the first xsl:when element that is true are processed. • The Java and C++ default statement is equivalent to the xsl:otherwise element.