booleanflags:ToBoolean

Previous Next

Attempts to convert a string to boolean true() or boolean false() by applying a special "flag-based string-to-boolean conversion" principle. This principle consists of using an internal list that is a mapping between string values and truth values.

You can view this internal list by calling the booleanflags:Show() function. You can add to this list by calling the pc:define-boolean-flags directive.

The "flag-based string-to-boolean conversion" principle contrasts with the XSLT 1.0 rules for string-to-boolean conversion, which state that any non-empty string converts to true() and only the empty string converts to false() .

The flag-based conversion is performed case-insensitively. If yes is associated to boolean true(), then so are Yes and YES.

Syntax

booleanflags:ToBoolean( string )

The required string is the string value that you want to convert using "flag-based string-to-boolean conversion".

 

Example

This example returns the text "Executed verbosely" if the runtime user passes one of the following on the command line:

verbose=true

verbose=yes

 

but not if he passes one of the following, or nothing at all:

verbose=false

verbose=no

 

The booleanflags:ToBoolean() function is necessary to get this behaviour. If it were omitted, the text "Executed verbosely" would always appear because the test would be whether or not the verbose variable had a non-empty string as a value. This is always the case because of the pc:assign-var-default line.

<example xmlns:pc="Processing.Command">
  <pc:assign-var-default verbose="no"/>
  <pc:if-then test="booleanflags:ToBoolean($verbose)">
      Executed verbosely
  </pc:if-then>
</example>

 

See also

pc:assign-boolean

pc:assign-boolean-default

booleanflags:Show

Implicit XPath datatype conversion