Choosing an XPath conditional expression that tests for a nil value in a transform
Use the XPath functions fn:empty, fn:nilled, or fn:exists to test if an output element is set to nil. You can use these functions to define conditional expressions in a transform.
About this task
For example, you can use fn:empty, fn:nilled, or fn:exists as part of conditional expression that determines if a transform is applied. You can also use these transforms as part of the conditional expressions that you set in an IF transform.
Procedure
XPath function | Usage | Source element | Output |
---|---|---|---|
fn:empty |
Tests whether a set of elements is empty |
A single XML or non-XML element that is present and nilled |
false |
fn:empty |
Tests whether a set of elements is empty |
A NULL value in a logical tree |
false |
fn:empty |
Tests whether a set of elements is empty |
A missing element, not present in the logical tree |
true |
fn:nilled |
Tests whether an element is nilled |
A nillable XML element |
true only if the xsi:nil attribute is present and set to 'true' in the logical tree |
fn:nilled |
Tests whether an element is nilled |
A nillable non-XML element |
true only if the value in the logical tree is NULL |
fn:exists |
Tests whether an element exists |
A single XML or non-XML element |
true if the element is present in the logical tree, regardless of the nillable and nilled state |
fn:exists |
Tests whether an element exists |
A NULL value in a logical tree |
true |
fn:exists |
Tests whether an element exists |
A missing element, not present in the logical tree |
false |
Example
This example shows an XPath expression that checks if an input element is nilled.
The XPath expression evaluates to true when an input element is not set to nil.
Use the fn:nilled
XPath function to test whether the value of an input element
has the xsi:nil
attribute set.
xsi:nil
attribute set is considered to be
present.The XML schema for the element is the following:
<element name="BookName" type="string" nillable="true" ></element>
The XPath expression that you define is the following:
fn:nilled( $BookName)