XPath - Boolean Functions Examples

Function boolean converts its argument to a boolean as follows:
- a number is true if and only if it is neither positive or negative zero nor NaN
- a node-set is true if and only if it is non-empty
- a string is true if and only if its length is non-zero
- an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type
1. boolean(//perm[position()=5]/@id)
..........
<perm type="admin" id="1">POReqSend</perm>
<perm type="cert" id="cert_1">CA_CERTS</perm>
<perm type="cert" id="cert_2">SYSTEM_CERTS</perm>
<perm type="template">POConfirmSend.xfm</perm>
--> <perm type="admin" id="2">POQueryApprover</perm>
<perm type="businessprocess">PO.bp</perm>
<perm>permission_1</perm>
<perm>permission_2</perm>
..........
As value of id attribute of the fifth perm element is a number, boolean function will return true.
Result: true
2. boolean(Data/username/text())
<Data>
<PrimaryDocument SCIObjectID="serverName:6546ef:f8ca28794b:-3ae6"/>
<username>Joe</username>
..........
As content of element username exist and it is a string, boolean function will return true.
Result: true
3. boolean(Data/PrimaryDocument/text())
<Data>
<PrimaryDocument SCIObjectID="serverName:6546ef:f8ca28794b:-3ae6"/>
<username>Joe</username>
..........
As element PrimaryDocument does not contain any content, boolean function will return false.
Result: false
4. not(Data[username/text() = 'Joe'])
<Data>
<PrimaryDocument SCIObjectID="serverName:6546ef:f8ca28794b:-3ae6"/>
<username>Joe</username>
..........
Result: false
5. not(Data[username/text() = 'Joe_123'])
<Data>
<PrimaryDocument SCIObjectID="serverName:6546ef:f8ca28794b:-3ae6"/>
<username>Joe</username>
..........
Result: true