Saxon.Api

 

 

Saxon.Api

Class Predicates


public class Predicates

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

Method Summary

static IPredicate<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> IPredicate<TInput> Empty(Step<TInput, TResult> step)

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

static IPredicate<XdmAtomicValue> Eq(XdmAtomicValue value2)

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

static IPredicate<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> IPredicate<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> IPredicate<TInput> Every(Step<TInput, TResult> step, IPredicate<TResult> condition)

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

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

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

static IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<XdmNode> HasNamespace(string uri)

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

static IPredicate<XdmItem> IsArray()

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

static IPredicate<XdmItem> IsAtomic()

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

static IPredicate<XdmItem> IsAttribute()

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

static IPredicate<XdmItem> IsComment()

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

static IPredicate<XdmItem> IsDocument()

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

static IPredicate<XdmItem> IsElement()

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

static IPredicate<XdmItem> IsFunction()

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

static IPredicate<XdmItem> IsMap()

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

static IPredicate<XdmItem> IsNamespace()

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

static IPredicate<XdmItem> IsNode()

A predicate to test whether an item is a node.

static IPredicate<XdmItem> IsProcessingInstruction()

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

static IPredicate<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> IPredicate<TInput> Not(IPredicate<TInput> condition)

Return an IPredicate that is the negation of a supplied IPredicate.

static <TInput, TResult> IPredicate<TInput> Some(Step<TInput, TResult> step, IPredicate<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

AttributeEq

public static IPredicate<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 IPredicate<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 IPredicate<XdmAtomicValue> Eq(XdmAtomicValue value2)

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

Parameters:

value2 - 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 IPredicate<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 IPredicate<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 as string value equal to the given string.

Every

public static IPredicate<TInput> Every<TInput, TResult>(Step<TInput, TResult> step,
IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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

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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<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 IPredicate<TInput> Not<TInput>(IPredicate<TInput> condition)

Return an IPredicate that is the negation of a supplied IPredicate.

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 IPredicate<TInput> Some<TInput, TResult>(Step<TInput, TResult> step,
IPredicate<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.