Comparisons

The simplest comparison operators are eq, ne, lt, le, gt, ge. These compare two atomic values of the same type, for example two integers, two dates, or two strings. (Collation hasn’t been implemented in current version of PsychoPath). If the operands are not atomic values, an error is raised.

The operators =''', !=' , '<=' , '> , '''<, and >= can compare arbitrary sequences. The result is true if any pair of items from the two sequences has the specified relationship, for example $A = $B is true if there is an item in $A that is equal to some item in $B.

The operators is and isnot test whether the operands represent the same (identical) node. For example, title 1 is * @note 1 is true if the first title child is the first child element that has a @note attribute. If either operand is an empty sequence the result is an empty sequence (which will usually be treated as false).

The operators << and >> test whether one node precedes or follows another in document order. Consider this XML document (XPexample.xml): <source lang="xml">

<book>
 <title>Being a Dog Is a Full-Time Job</title>
 <author>Charles M. Schulz</author>
 <character>
   <name>Snoopy</name>
   <friend-of>Peppermint Patty</friend-of>
   <since>1950-10-04</since>
   <age>2</age>
   <qualification>extroverted beagle</qualification>
 </character>
 <character>
   <name>Peppermint Patty</name>
   <since>1966-08-22>/since>
   <age>4</age>
   <qualification>bold, brash and tomboyish</qualification>
 </character>
</book>

This file conforms to the following Schema (XPexample.xsd):

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified">

 <xs:element name="book">
   <xs:complexType>
     <xs:sequence>
       <xs:element ref="title" />
       <xs:element ref="author" />
       <xs:element maxOccurs="unbounded" ref="character" />
     </xs:sequence>
   </xs:complexType>
 </xs:element>

 <xs:element name="title" type="characterName"></xs:element>

 <xs:element name="author" type="characterName"></xs:element>

 <xs:element name="character">
   <xs:complexType>
     <xs:sequence>
       <xs:element ref="name" />
       <xs:element ref="friend-of" minOccurs="0" />
       <xs:element ref="since" />
       <xs:element ref="age" />
       <xs:element ref="qualification" />
     </xs:sequence>
   </xs:complexType>
 </xs:element>
 <xs:element name="name" type="characterName" />
 <xs:element name="friend-of" type="characterName" />
 <xs:element name="since" type="xs:date" />
 <xs:element name="age" type="xs:nonNegativeInteger" />
 <xs:element name="qualification" type="xs:string" />

 <xs:simpleType name="characterName">
   <xs:restriction base="xs:normalizedString">
     <xs:minLength value="1"/>
   </xs:restriction>
 </xs:simpleType>
</xs:schema>

Examples:

book/character[name="Snoopy"] &lt;&lt; book/character[name="Peppermint Patty"] 

result:

  1. xs:boolean: true

book/character[name="Peppermint Patty"] &lt;&lt; book/character[name="Snoopy"]

result:

  1. xs:boolean: false