AndExpr

Check if one or more Boolean operands are all true.


Syntax

AndExpr

EqualityExpr | AndExpr and EqualityExpr

Description

If all of the operands evaluate to the Boolean value "true", then "true" is returned, otherwise "false".

Compatibility

The operator name must be specified using lower case.

It corresponds to the expression AndExpr defined in XPath, Section 3.4, Rule 22, but is extended by BetweenExpr. This allows SequenceExpr and ProximityExpr to be used as operands in an AndExpr.

Examples

  • Select all patients born in 1950 and living in Bradford (all patient nodes that satisfy the following predicate expression: there is an immediate child node born whose numeric value equals 1950 and there is also a descendant child node city whose string value equals "Bradford"):

    /patient[born = 1950 and .//city = 'Bradford']
  • Select all patients born in 1950 having a phone number:

    /patient[born = 1950 and (address/* after postcode)[position() != last()]]
    

    This query demonstrates that you can use a filtered SequenceExpr inside an AndExpr. It effectively selects all patient nodes for which all the following conditions must be met:

    • it has a child element node born whose numeric value equals 1950

    • it has a child element node address

    • the address node has at least three child element nodes that must satisfy these conditions:

      • one of these child nodes has the name postcode

      • a sibling node of postcode must exist whose position is not the last

    There are six possible child nodes for address which in document order are street, housenumber, city, postcode, country, and phone. Because of the second predicate expression there must be at least two nodes following a postcode node, but if this is true, then it can only be a phone node.

    Naturally you can write such a condition much more simply:

    /patient[born = 1950 and address/phone]

    This query is somewhat faster, since Tamino does not have to expand address/* (a NameTest) and there is no need to call two functions used in the nested predicate expression. The second condition is evaluated to "true" if an element node phone exists that is a child element of address which in turn is a child element of a patient node.

Related Functions

BetweenExpr