Name

true()

Always returns the boolean value true. Remember that the strings "true" and "false" don’t have any special significance in XSLT. This function (and the false() function) allow you to generate boolean values when you need them.

Syntax

[1.0] boolean true()
[2.0] xs:boolean true()

Inputs

None.

Output

The boolean value true.

Defined in

[1.0] XPath section 4.3, “Boolean Functions.”

[2.0] XQuery 1.0 and XPath 2.0 Functions and Operators section 9.1, “Additional Boolean Constructor Functions.”

Example

Here’s a brief example that uses the true() function:

<?xml version="1.0"?>
<!-- true.xsl -->
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:text>&#xA;A test of the true() function:&#xA;&#xA;</xsl:text>

    <xsl:text>  true() returned </xsl:text>
    <xsl:value-of select="true()"/>
    <xsl:text>!</xsl:text>
  </xsl:template>
</xsl:stylesheet>

When using this stylesheet against any XML document, it generates this less-than-exciting result:

A test of the true() function:

  true() returned true!

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.