Saxon.Api

 

 

Saxon.Api

Class Predicates


public class Predicates

This non-instantiable class provides a number of useful implementations of the System.Predicate interface, designed for use when navigating streams of XDM items.

Method Summary

static <T> Predicate<T> AllOf (Predicate[]<T> conditions)

A predicate to test whether all the supplied predicates are satisfied

static <T> Predicate<T> AnyOf (Predicate[]<T> conditions)

A predicate to test whether at least one of the supplied predicates are satisfied

static Predicate<XdmNode> AttributeEq (string local, string value)

Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace) whose string value is equal to a given value.

static <TInput, TResult> Predicate<TInput> Empty (Step<TInput, TResult> step)

Obtain a predicate that tests whether a supplied Step delivers an empty result.

static Predicate<XdmAtomicValue> Eq (XdmAtomicValue value)

Obtain a predicate that tests whether an atomic value compares equal to a supplied atomic value of a comparable type.

static Predicate<XdmItem> Eq (string value)

Obtain a predicate that tests whether the result of applying the XPath string() function to an item is equal to a given string.

static <TInput, TResult> Predicate<TInput> Eq (Step<TInput, TResult> step, string value)

Obtain a predicate that tests whether there is some item in the result of applying a step, whose string value is equal to a given string. For example, Eq(attribute("id"), "foo") matches an element if it has an "id" attribute whose value is "foo".

static <TInput, TResult> Predicate<TInput> Every (Step<TInput, TResult> step, Predicate<TResult> condition)

Obtain a predicate that tests whether every item in the result of applying a step satisfies the supplied condition.

static Predicate<XdmItem> Exists (Step<XdmItemXdmItem> step)

Obtain a predicate that tests whether a supplied Step delivers a non-empty result.

static Predicate<XdmNode> HasAttribute (string local)

Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace).

static Predicate<XdmNode> HasLocalName (string localName)

Obtain a predicate that tests whether an item is a node with a given local name, irrespective of the namespace.

static Predicate<XdmNode> HasName (string uri, string localName)

Obtain a predicate that tests whether an item is a node with a given namespace URI and local name.

static Predicate<XdmNode> HasNamespace (string uri)

Obtain a predicate that tests whether an item is a node with a given namespace URI.

static Predicate<XdmItem> IsArray ()

A predicate to test whether an item is an XDM array.

static Predicate<XdmItem> IsAtomic ()

A predicate to test whether an item is an atomic value.

static Predicate<XdmItem> IsAttribute ()

A predicate to test whether an item is an attribute node.

static Predicate<XdmItem> IsComment ()

A predicate to test whether an item is a comment node.

static Predicate<XdmItem> IsDocument ()

A predicate to test whether an item is a document node.

static Predicate<XdmItem> IsElement ()

A predicate to test whether an item is an element node.

static Predicate<XdmItem> IsFunction ()

A predicate to test whether an item is a function value (this includes maps and arrays).

static Predicate<XdmItem> IsMap ()

A predicate to test whether an item is an XDM map.

static Predicate<XdmItem> IsNamespace ()

A predicate to test whether an item is a namespace node.

static Predicate<XdmItem> IsNode ()

A predicate to test whether an item is a node.

static Predicate<XdmItem> IsProcessingInstruction ()

A predicate to test whether an item is a processing instruction node.

static Predicate<XdmItem> IsText ()

A predicate to test whether an item is a text node.

static Predicate<XdmItem> MatchesRegex (string regex)

Obtain a predicate that tests whether the result of applying the XPath string() function to an item matches a given regular expression.

static <TInput> Predicate<TInput> Not (Predicate<TInput> condition)

Return a Predicate that is the negation of a supplied Predicate.

static <TInput, TResult> Predicate<TInput> Some (Step<TInput, TResult> step, Predicate<TResult> condition)

Obtain a predicate that tests whether there is some item in the result of applying a step that satisfies the supplied condition.

 

Method Detail

AllOf

public static Predicate<T> AllOf<T>(Predicate[]<T> conditions)

A predicate to test whether all the supplied predicates are satisfied

Parameters:

conditions - The predicates that must all be satisfied

Returns:

A predicate that evaluates to true only if all the supplied predicates are satisfied

AnyOf

public static Predicate<T> AnyOf<T>(Predicate[]<T> conditions)

A predicate to test whether at least one of the supplied predicates are satisfied

Parameters:

conditions - The predicates, one of which must be satisfied

Returns:

A predicate that evaluates to true only if all the supplied predicates are satisfied

AttributeEq

public static Predicate<XdmNode> AttributeEq(string local,
string value)

Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace) whose string value is equal to a given value.

Parameters:

local - The required attribute name
value - The required attribute value

Returns:

A predicate that returns true if and only if the supplied item is an element having an attribute with the given local name, in no namespace, whose string value is equal to the given value.

Empty

public static Predicate<TInput> Empty<TInput, TResult>(Step<TInput, TResult> step)

Obtain a predicate that tests whether a supplied Step delivers an empty result.

Parameters:

step - A step to be applied to the item being tested

Returns:

A predicate that returns true if the supplied step returns an empty result.

Eq

public static Predicate<XdmAtomicValue> Eq(XdmAtomicValue value)

Obtain a predicate that tests whether an atomic value compares equal to a supplied atomic value of a comparable type.

Parameters:

value - The atomic value to be compared with

Returns:

A predicate which returns true when applied to a value that is equal to the supplied value under the "is-same-key" comparison rules. (These are the rules used to compare key values in an XDM map. The rules are chosen to be context-free, error-free, and transitive.)

Eq

public static Predicate<XdmItem> Eq(string value)

Obtain a predicate that tests whether the result of applying the XPath string() function to an item is equal to a given string.

Parameters:

value - The string being tested

Returns:

A predicate which returns true if the string value of the item being tested is equal to the given string under Java comparison rules for comparing strings.

Eq

public static Predicate<TInput> Eq<TInput, TResult>(Step<TInput, TResult> step,
string value)

Obtain a predicate that tests whether there is some item in the result of applying a step, whose string value is equal to a given string. For example, Eq(attribute("id"), "foo") matches an element if it has an "id" attribute whose value is "foo".

Parameters:

step - The step to be evaluated
value - The string to be compared against the items returned by the step

Returns:

A predicate which returns true if some item selected by the step has a string value equal to the given string.

Every

public static Predicate<TInput> Every<TInput, TResult>(Step<TInput, TResult> step,
Predicate<TResult> condition)

Obtain a predicate that tests whether every item in the result of applying a step satisfies the supplied condition.

For example, every(CHILD, exists(attribute("foo")) matches an element if each of its child elements has an attribute whose local name is "foo".

If the step returns an empty sequence the result will always be true.

Parameters:

step - The step to be evaluated
condition - The predicate to be applied to the items returned by the step

Returns:

A predicate which returns true if every item selected by the step satisfies the supplied condition.

Exists

public static Predicate<XdmItem> Exists(Step<XdmItemXdmItem> step)

Obtain a predicate that tests whether a supplied Step delivers a non-empty result.

Parameters:

step - A step to be applied to the item being tested

Returns:

A predicate that returns true if the step returns a non-empty result.

HasAttribute

public static Predicate<XdmNode> HasAttribute(string local)

Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace).

Parameters:

local - The required attribute name

Returns:

A predicate that returns true if and only if the supplied item is an element having an attribute with the given local name, in no namespace.

HasLocalName

public static Predicate<XdmNode> HasLocalName(string localName)

Obtain a predicate that tests whether an item is a node with a given local name, irrespective of the namespace.

Parameters:

localName - The required local name. If the zero-length string is supplied, the predicate matches nodes with no name, such as namespace nodes for the default namespace.

Returns:

A predicate that returns true if and only if the supplied item is a node with the given namespace URI and local name.

HasName

public static Predicate<XdmNode> HasName(string uri,
string localName)

Obtain a predicate that tests whether an item is a node with a given namespace URI and local name.

Parameters:

uri - The required namespace URI: supply a zero-length string to indicate the null namespace
localName - The required local name

Returns:

A predicate that returns true if and only if the supplied item is a node with the given namespace URI and local name.

HasNamespace

public static Predicate<XdmNode> HasNamespace(string uri)

Obtain a predicate that tests whether an item is a node with a given namespace URI.

Parameters:

uri - The required namespace URI: supply a zero-length string to identify the null namespace

Returns:

A predicate that returns true if and only if the supplied item is a node with the given namespace URI. If a zero-length string is supplied, the predicate will also match nodes having no name, such as text and comment nodes, and nodes having a local name only, such as namespace and processing-instruction nodes.

IsArray

public static Predicate<XdmItem> IsArray()

A predicate to test whether an item is an XDM array.

Returns:

A predicate that returns true if given an item that is an array.

IsAtomic

public static Predicate<XdmItem> IsAtomic()

A predicate to test whether an item is an atomic value.

Returns:

A predicate that returns true if given an item that is an atomic value.

IsAttribute

public static Predicate<XdmItem> IsAttribute()

A predicate to test whether an item is an attribute node.

Returns:

A predicate that returns true if given an item that is an attribute node.

IsComment

public static Predicate<XdmItem> IsComment()

A predicate to test whether an item is a comment node.

Returns:

A predicate that returns true if given an item that is a comment node.

IsDocument

public static Predicate<XdmItem> IsDocument()

A predicate to test whether an item is a document node.

Returns:

A predicate that returns true if given an item that is a document node.

IsElement

public static Predicate<XdmItem> IsElement()

A predicate to test whether an item is an element node.

Returns:

A predicate that returns true if given an item that is an element node.

IsFunction

public static Predicate<XdmItem> IsFunction()

A predicate to test whether an item is a function value (this includes maps and arrays).

Returns:

A predicate that returns true if given an item that is a function, including maps and arrays.

IsMap

public static Predicate<XdmItem> IsMap()

A predicate to test whether an item is an XDM map.

Returns:

A predicate that returns true if given an item that is a map.

IsNamespace

public static Predicate<XdmItem> IsNamespace()

A predicate to test whether an item is a namespace node.

Returns:

A predicate that returns true if given an item that is a namespace node.

IsNode

public static Predicate<XdmItem> IsNode()

A predicate to test whether an item is a node.

Returns:

A predicate that returns true if given an item that is a node.

IsProcessingInstruction

public static Predicate<XdmItem> IsProcessingInstruction()

A predicate to test whether an item is a processing instruction node.

Returns:

A predicate that returns true if given an item that is a processing instruction node.

IsText

public static Predicate<XdmItem> IsText()

A predicate to test whether an item is a text node.

Returns:

A predicate that returns true if given an item that is a text node.

MatchesRegex

public static Predicate<XdmItem> MatchesRegex(string regex)

Obtain a predicate that tests whether the result of applying the XPath string() function to an item matches a given regular expression.

Parameters:

regex - The regular expression (this is a Java regular expression, not an XPath regular expression)

Returns:

A predicate which returns true if the string value of the item being tested contains a substring that matches the given regular expression. To test the string in its entirety, use anchors "^" and "$" in the regular expression.

Not

public static Predicate<TInput> Not<TInput>(Predicate<TInput> condition)

Return a Predicate that is the negation of a supplied Predicate.

Parameters:

condition - The supplied predicate

Returns:

A predicate that matches an item if and only if the supplied predicate does not match the item.

Some

public static Predicate<TInput> Some<TInput, TResult>(Step<TInput, TResult> step,
Predicate<TResult> condition)

Obtain a predicate that tests whether there is some item in the result of applying a step that satisfies the supplied condition.

For example, some(CHILD, exists(attribute("foo")) matches an element if it has a child element with an attribute whose local name is "foo".

If the step returns an empty sequence the result will always be false.

Parameters:

step - The step to be evaluated
condition - The predicate to be applied to the items returned by the step

Returns:

A predicate which returns true if some item selected by the step satisfies the supplied condition.