variable:TypeOf

Previous Next

Returns the name of the XSLT 1.0 data type that a given variable is currently cast to.

The return value is one of the string values nodeset, string, number, boolean.

variable:TypeOf( xpath >> string )

The required xpath must evaluate to a string that is the name of an instantiated variable. If there is no instantiated variable by that name, the return value is nodeset.

Example 1

The result of the following is boolean:

<pc:assign-var defined="{true()}" />
<pc:assign-var mytype="{variable:TypeOf($defined)}"/>
<pc:value-of select="$mytype"/>

 

Example 2

A variable may be initialised and have the empty string ( '' ) as a value. The result of the following is string:

<pc:assign-var defined="" />
<pc:assign-var mytype="{variable:TypeOf($defined)}"/>
<pc:value-of select="$mytype"/>

 

Example 3

The result of the following, where no variable by the name of "defined" is instantiated, is nodeset:

<pc:assign-var mytype="{variable:TypeOf($defined)}"/>
<pc:value-of select="$mytype"/>