Function and Operator Reference


The XPath 2.0 functions and operators described in this reference content are supported by the Verastream Process Design Studio graphical user interface and the Verastream Process Server. The Process Design Studio also provides a source view in which XML can be edited directly and additional functions may be used. Use of unsupported functions may create unexpected results in the graphical user interface, and during process deployment and execution, and is therefore not recommended.

Descriptions and examples are taken from the W3 XPath Version 2.0 Specification.

The following function help uses descriptive names for the arguments that are passed to functions. For example, an argument named 'aString' would accept a single string value, and an argument whose name includes 'optional' may be omitted.

Functions

Operators

BPEL Functions

bpel:getVariableProperty(variableName, propertyName)

Returns the value of the property specified from within the variable specified.

bpel:doXslTransform(templateURI, nodeSet, optionalXSLTparam, optionalXSLTparamValue)

Uses an XSL stylesheet specified by templateURI to transform a nodeset. The templateURI argument requires a string value that provides the URI for an XSL stylesheet. The nodeSet argument specifies the source nodeset to transform. optionalXSLTparam and optionalXSLTparamValue may be used to specify the name of an XSL parameter (param), and a value to be stored in it. If one of the optional parameters is used, they must both be used, as they comprise a name/value pair. If the optional parameters are used, the XSL stylesheet must include a global (top-level) parameter (param) whose name matches the value of the optionalXSLTparam argument.

Example: bpel:doXslTransform("myProject:/myXSLStylesheets/SA1.xsl", $aNodeSet) returns a nodeset with the contents of $aNodeSet transformed by the rules in SA1.xsl.

Boolean Functions

W3 Recommendation for XPath Version 2.0 Boolean Functions.

boolean(item_sequence)

Evaluates the argument passed appropriately for its type and returns a boolean value as follows:

If the function does not return true, it returns false.

not(item_sequence)

Returns true if the boolean value passed is false; false otherwise.

true()

Returns the boolean value, true.

false()

Returns the boolean value, false.

Date/Time Functions

W3 Recommendation for XPath Version 2.0 Date/Time Functions. Examples in this section are taken from the W3 specification. There are more examples available at the link.

adjust-date-to-timezone(date)

Returns a date value equivalent to the original date, but with the timezone removed. If the timezone value is empty, returns a date without a timezone.

Example: fn:adjust-time-to-timezone(xs:time("10:00:00")) returns 10:00:00-05:00.

Example: fn:adjust-date-to-timezone(xs:date("2002-03-07"), $tz) returns 2002-03-07-10:00.

adjust-date-to-timezone(date,timezone)

Returns a date value equivalent to the original date, but with a different timezone.

adjust-dateTime-to-timezone(dateTime)

Returns a date-time value equivalent to the original date-time, but with the timezone removed.

Example: fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00")) returns 2002-03-07T10:00:00-05:00.

Example: fn:adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"), xs:dayTimeDuration("PT10H")) returns 2002-03-08T03:00:00+10:00.

adjust-dateTime-to-timezone(dateTime, timezone)

Returns a date-time value equivalent to the original value, but with a different timezone.

adjust-time-to-timezone(time)

Returns a time value equivalent to the original time, but with the timezone removed.

Example: fn:adjust-time-to-timezone(xs:time("10:00:00")) returns 10:00:00-05:00.

Example: fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"), xs:dayTimeDuration("PT10H")) returns 03:00:00+10:00.

adjust-time-to-timezone(time, timezone)

Returns a time value equivalent to the original time, but with a different timezone.

current-date()

Returns the current date.

Example: fn:current-date() returns an xs:date corresponding to the current date and time. fn:current-date() might return 2004-05-12+01:00.

current-dateTime()

Returns the current date and time. This does not change during the execution of the query or transformation.

Example: fn:current-dateTime() returns the current date and time. fn:current-dateTime() might return 2004-05-12T18:17:15.125Z corresponding to the current time on May 12, 2004 in timezone Z.

current-time()

Returns the current time. This does not change during the execution of the query or transformation.

Example: fn:current-time() returns a time corresponding to the current date and time. For example, an invocation of fn:current-time() might return 23:17:00.000-05:00.

 

dateTime(date, time)

Combines the given date and time. The result has a timezone if either of the inputs has a timezone; if they both have a timezone, then the two timezones must be the same.

day-from-date(date)

Retrieves the day component from the date value.

Example: fn:day-from-date(xs:date("1999-05-13-05:00")) returns 13.

day-from-dateTime(dateTime)

Retrieves the day component of a date-time value.

Example: fn:day-from-dateTime(xs:dateTime("1999-12-7T20:00:00-05:00")) returns 7.

days-from-duration(dayTimeDuration)

Retrieves the day component of a day-time-duration value.

Example: fn:days-from-duration(xs:dayTimeDuration("P3DT10H")) returns 3.

 

hours-from-dateTime(dateTime)

Retrieves the hour component of a date-time value.

Example: fn:hours-from-dateTime(xs:dateTime("1999-05-31T08:20:00-05:00")) returns 8.

hours-from-duration(dayTimeDuration)

Retrieves the hours component of a date-time-duration value.

Example: fn:hours-from-duration(xs:dayTimeDuration("P3DT10H")) returns 10.

hours-from-time(time)

Retrieves the hours component of a time value. This is derived from the localized value, not the normalized value: for example if the supplied time value is 01:23:00+05:00 then the result is 1.

Example: fn:hours-from-time(xs:time("11:23:00")) returns 11.

implicit-timezone()

Returns the implicit timezone. The implicit timezone is the timezone determined by the system clock when the configuration object is instantiated, thus ensuring that the implicit timezone is known during compilation.

 

minutes-from-dateTime(dateTime)

Retrieves the minutes component of the date-time value.

Example: fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns 20.

minutes-from-duration(dayTimeDuration)

Retrieves the minutes component of a day-time-duration value.

Example: fn:minutes-from-duration(xs:dayTimeDuration("P3DT10H")) returns 0.

minutes-from-time(time)

Retrieves the minutes component of a time value.

Example: fn:minutes-from-time(xs:time("1999-05-31T13:20:00-05:00")) returns 0.

 

month-from-date(date)

Provides the month component of the date value.

Example: fn:month-from-date(xs:date("1999-05-31-05:00")) returns 5.

month-from-dateTime(dateTime)

Provides the month component of the date-time value.

Example: fn:month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns 5.

months-from-duration(dayMonthDuration)

Retrieves the months component of a year-month-duration value.

Example: fn:months-from-duration(xs:yearMonthDuration("P20Y15M")) returns 3.

 

seconds-from-dateTime(dateTime)

Retrieves the seconds component of the date-time value.

Example: fn:seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns 0.

seconds-from-duration(dayTimeDuration)

Retrieves the seconds component of the day-time-duration value.

Example: fn:seconds-from-duration(xs:dayTimeDuration("P3DT10H12.5S")) returns 12.5.

seconds-from-time(time)

Retrieves the seconds component of the time value.

Example: fn:seconds-from-time(xs:time("13:20:10.5")) returns the xs:dayTimeDuration whose value is -PT5H.

 

timezone-from-date(date)

Retrieves the timezone component of the date value.

Example: fn:timezone-from-date(xs:date("1999-05-31-05:00")) returns 10.5.

timezone-from-dateTime(dateTime)

Retrieves the timezone component of the date-time value.

Example: fn:timezone-from-dateTime(xs:dateTime("2000-06-12T13:20:00Z")) returns xs:dayTimeDuration whose value is PT0S..

timezone-from-time(time)

Retrieves the timezone component of the time value.

Example: fn:timezone-from-time(xs:time("13:20:00")) returns 0.

 

year-from-date(date)

Retrieves the year component of the date value.

Example: fn:year-from-date(xs:date("1999-05-31")) returns 1999.

year-from-dateTime(date)

Retrieves the year component of the date-time value.

Example: fn:year-from-dateTime(xs:dateTime("1999-12-31T24:00:00")) returns 2000.

years-from-duration(yearMonthDuration)

Retrieves the years component of the year-month-duration value.

Example: fn:years-from-duration(xs:yearMonthDuration("P20Y15M")) returns 21.

Name Functions

W3 Recommendation for XPath Version 2.0 Name Functions. Examples given here are taken from the W3 specification and additional examples are available at the link.

QName(uri,localName)

QName stands for "qualified name" and is used as an identifier for elements and attributes. In XML documents, QNames are generally used to reference particular elements or attributes.

Example: fn:QName("http://www.example.com/example", "person") returns xs:QName with namespace URI = "http://www.example.com/example", local name = "person" and prefix = "".

base-uri()

Returns the value of the base URI of the context node.

base-uri(node)

Returns the value of the base URI of a given node.

document-uri(node)

Returns the URI of a document.

in-scope-prefixes(element)

Returns the names of the namespaces that are in scope for an element. All the names will be of type xs:NCName, except for the unnamed namespace, which is represented by the string "".

local-name()

Returns the local part of the name of the context node.

local-name-from-QName(qname)

Extracts the local name component of a QName value, as an xs:NCName.

Example: fn:local-name-from-QName(fn:QName("http://www.example.com/example", "person")) returns "person".

name(node)

Returns the name of a node as a string in the lexical form of a QName.

namespace-uri(nodes)

Returns the namespace URI of the name of a given node.

namespace-uri-for-prefix(prefix,element)

Returns the namespace URI that corresponds to a given prefix, using the namespaces that are in scope for a given element.

namespace-uri-from-QName(qname)

Extracts the namespace URI component of a QName value.

Example: fn:namespace-uri-from-QName(fn:QName("http://www.example.com/example", "person")) returns the namespace URI corresponding to "http://www.example.com/example".

node-name(node)

Retrieves the name of the given node, as a QName value (that is, a namespace URI plus local name).

prefix-from-QName(qname,element)

Retrieves the prefix component of a QName value. Returns an empty sequence if the QName has no prefix.

resolve-QName(qname,element)

Expands a lexical QName using the in-scope namespaces from the given element.

In this example, assume that the element bound to $element has a single namespace binding bound to the prefix eg.

Example: fn:resolve-QName("hello", ", $element)) returns a QName with local name "hello" that is in no namespace.

resolve-uri(relative)

Resolves a relative URI against the base URI from the static context.

resolve-uri(relative,base)

Resolves a relative URI against a given base URI.

static-base-uri()

Returns the base URI of the static context.

Node Set Functions

W3 Recommendation for XPath Version 2.0 Node-Set Functions.

avg(anyAtomicType_sequence)

Returns the average of a set of numbers or durations

collection()

This function passes a null URI to the registered CollectionURIResolver. The default CollectionURIResolver returns an empty sequence, but if you supply your own Collection URIResolver, it can handle this case however you want.

For more information. see XPath 2.0 Specification.

collection(string)

Loads an external collection of nodes identified by the URI of the collection. If a user-defined CollectionURIResolver has been registered, the action of this function is entirely user-defined.

A resolver may be registered using the setCollectionResolver() method on the Configuration object, or (in XSLT) using setAttribute() on the TransformerFactory. The CollectionURIResolver may be nominated using the -cr option on the command line.

count(item_sequence)

Counts the number of items in a sequence

data(item_sequence)

Returns the result of atomizing the supplied sequence

deep-equal(operand1, operand2)

Compares two sequences for deep equality; string values are compared using the default collation; nodes are compared for deep equality of names and content.

deep-equal(operand1, operand2, collation)

Compares two sequences for deep equality; string values are compared using the named collation; nodes are compared for deep equality of names and content.

default-collation()

Returns the name of the default collation. If no collation has been set explicitly the default will be the URI of the Unicode codepoint collation.

distinct-values(anyAtomicType_sequence)

Returns the set of distinct values present in a given sequence. This implementation returns the values in the order they first appear, but you cannot assume that this will always remain the case.

distinct-values(anyAtomicType_sequence, collation)

Returns the set of distinct values present in a given sequence, and compares strings using a named collation. This implementation returns the values in the order they first appear, but you cannot assume that this will always remain the case.

doc(uri)

Loads a document identified by its URI

For more information, see XPath 2.0 Specification.

doc-available(uri)

Returns true if a document with the given URI is successfully loaded, otherwise returns false.

 

empty(item_sequence)

Returns true if the given sequence is empty

error()

Raises an error.

error(error)

Raises an error. The first argument can an empty sequence, and is treated as an equivalent to calling fn:error() with no arguments. The error code (local part and namespace URI part) is recorded as part of the exception that's supplied to a user-defined JAXP ErrorListener, or that is returned to the calling application.

error(error, description)

Raises an error.

If supplied, the error code (local part and namespace URI part) is recorded as part of the exception that's supplied to a user-defined JAXP ErrorListener, or that is returned to the calling application. The value of the $description is available by calling getMessage() on the Exception object.

error(error, description, error-object_sequence)

Raises an error.

The value of the $description is available by calling getMessage() on the Exception object, and the object supplied in the third parameter is available from the getErrorObject() method.

For more information, see XPath 2.0 Specification.

exactly-one(item_sequence)

Checks whether value contains exactly one item; fails if it is empty or contains multiple items.

exists(item_sequence)

Returns true if the given sequence is not empty

 

id(string_sequence)

Finds the elements with given ID attribute values

id(string_sequence, node)

Finds the elements with given ID attribute values, within a specified document.

idref(string_sequence)

Finds the nodes that link to the element with a given ID value. These are element or attribute nodes marked by virtue of schema or DTD validation as IDREF or IDREFS values.

Example: id("foo bar") selects any elements with unique ID "foo" or "bar".

Example: id("foo")/child::para[5] selects the fifth para child of the element with unique ID "foo".

idref(string_sequence, node)

Finds the elements that link to the element with a given ID value. These will be element or attribute nodes marked by virtue of schema or DTD validation as IDREF or IDREFS values.

index-of(anyAtomicType_sequence, anyAtomicType)

Finds the positions of items in a sequence that match the second argument

index-of(anyAtomicType_sequence, anyAtomicType, collation)

Finds the positions of items in a sequence that match the second argument, using a named collation for the comparison

insert-before(item_sequence_target, position, item_sequence_inserts)

Insert an item into a sequence

 

lang(testLanguage)

Returns true if the xml:lang value for the context node matches the given language.

For example, if the context node is lang="en" or lang="en-us", the call lang("en") would return true.

lang(testLanguage, node)

Returns true if the xml:lang value for the given node matches the given language

last()

Returns the context size (the size of the sequence of items currently being processed)

Example: book[1]/author[last()] refers to the last <author> child of the first <book> element.

position()

Returns the numeric position of a node among its siblings.

count(nodeSet)

Returns the number of nodes in a nodeset.

 

max(anyAtomicType_sequence)

Returns the highest value in a sequence of comparable items

max(anyAtomicType_sequence, collation)

Returns the highest value in a sequence of strings, using a specified collation to perform the comparisons

min(anyAtomicType_sequence)

Returns the lowest value in a sequence of comparable items

min(anyAtomicType_sequence, collation)

Returns the lowest value in a sequence of strings, using a specified collation to perform the comparisons

name(nodeSet)

If passed an argument, name() returns the prefixed name of the first node in the nodeset. If the argument is ommitted, it defaults to a nodeset with the context node as its only member.

Example: name(//homepage/@xlink:href) returns xlink:href

nilled(node)

Returns true if the argument is an element that has the "nilled" property.

For more information, see XPath 2.0 Specification

one-or-more(item_sequence)

Tests whether $srcval contains one or more items; fails if it is an empty sequence.

position()

Returns the context position (that is, the position of the context item in the sequence currently being processed)

remove(item_sequence, position)

Removes the item at a given position in a sequence.

reverse(item_sequence)

Reverses the order of the items in the input sequence.

root()

Returns the root node (typically but not necessarily a document node) of the tree containing the context node

root(node)

Returns the root node (typically but not necessarily a document node) of the tree containing the given node

 

subsequence(item_sequence, startPosition)

Returns those items in the given sequence from the given starting position to the end of the sequence

subsequence(item_sequence, startPosition, length)

Returns those items in the given sequence from the given starting position up to the position implied by the given length

sum(anyAtomicType_sequence)

Returns the total of a sequence of numbers or durations. (The W3C specification lists this function in the Number category. It is used exclusively with nodesets, however, so Process Design Studio groups it in the nodeset category.)

sum(anyAtomicType_sequence, zero)

Returns the total of a sequence of numbers, specifying the value to be returned for an empty sequence

For more information, see XPath 2.0 Specification

trace(item_sequence, message)

Returns the value of the first argument after outputting a diagnostic message.

This implementation outputs the value of each item in a sequence as it is evaluated (except when the sequence is empty, in which case it outputs "empty sequence" at the start). Atomic values are output by converting them to a string, nodes by calling getPath() to generate a path expression to the node. With complex expressions the order of evaluation may be rather different from the expected order. The trace output is directed to System.err, this may be redirected by using "2>log.txt" on the command line. If a TraceListener has been nominated, then instead of writing the output to System.err, the information instead results in events being notified to the TraceListener.

unordered(item_sequence)

Returns a random permutation of its argument. Basically the function returns the value of its argument unchanged. The only important case where this function has any effect is where the sequence supplied as argument is a Step using a reverse axis: for example, unordered(ancestor::*) returns the ancestors in reverse document order. But applications should not rely on the actual order; the function is intended to be used by applications that do not care about the order of the results.

zero-or-one(item_sequence)

Tests whether $srcval contains zero or one items; fails if it contains multiple items.

Number Functions

W3 Recommendation for XPath Version 2.0 Number Functions.

number(object)

Returns a number based on the object passed to it, as follows:

number(item)

Converts the given value to a number, after atomization if necessary. Returns NaN if conversion is not possible.

floor(aNumber)

Returns a number equal to the argument rounded down to the nearest integer.

ceiling(aNumber)

Returns a number equal to the argument rounded up to the nearest integer.

round(aNumber)

Returns a number equal to the argument rounded to the nearest integer. If two integers are equally close to the argument, round() returns the larger of the two. Passing the following arguments return special cases:

abs(numeric)

Returns the absolute value of a given number. Returns the same type as the supplied argument.

Example: fn:abs(10.5) returns 10.5.

Example: fn:abs(-10.5) returns 10.5.

round-half-to-even(numeric)

Rounds a numeric value to the nearest whole number, rounding x.5 towards the nearest even number. In the case of doubles and floats, rounding errors may occur giving unexpected effects.

Example: fn:round-half-to-even(0.5) returns 0.

round-half-to-even(numeric, precision)

Rounds a numeric value to the nearest integer multiple of 10 the power of minus precision, rounding x.5 towards the nearest number whose last digit is even. In the case of doubles and floats, rounding errors may occur giving unexpected effects.

ODE Functions

The ODE functions listed here are specific to the Apache ODE runtime environment, the technology used by Verastream Process Server.

ode:split-to-elements(stringToSplit, separator, targetElement, optionalTargetNamespace)

Uses the separator value to split the value passed in stringToSplit, then creates a node of a type specified in targetElement from each result and returns the resulting nodeset. The optionalTargetNamespace argument adds a namespace attribute with the specified value to each element.

Example: ode:split-to-elements("Fred, Tom, Jane", ",", "firstName") will return a nodeset consisting of <firstName>Fred</firstName>, <firstName>Tom</firstName> and <firstName>Jane</firstName>.

ode:insert-before(context, children, siblings)

The context is the nodeset that the siblings argument will be inserted into, at a location determined by the children argument. This function finds the nodes passed in the children argument within the specified context; inserts the node(s) passed in the siblings argument before the first node of children, and returns the result. This function does not alter the context argument. Instead, it creates a copy with the requested modification.

ode:insert-after(context, children, siblings)

The context is the nodeset that the siblings argument will be inserted into, at a location determined by the children argument. This function finds the nodes passed in the children argument within the specified context; inserts the node(s) passed in the siblings argument after the last node of children, and returns the result. This function does not alter the context argument. Instead, it creates a copy with the requested modification.

ode:insert-as-first-into(context, children)

Creates a copy of the node passed in the context argument and adds the node(s) passed in the children argument at the beginning. Returns the result.

ode:insert-as-last-into(context, children)

Creates a copy of the node passed in the context argument and adds the node(s) passed in the children argument at the end. Returns the result.

ode:delete(context, children)

Creates a copy of the node passed in the context argument and deletes the node(s) passed in the children argument. Returns the result.

ode:rename(context, name)

Creates a copy of the node passed in the context argument and names it with the value passed in the name argument. Returns the result.

ode:json-to-xml(jsonToConvert, targetElement, optionalTargetNamespace)

This function converts a JSON string (specified by the jsonToConvert argument) into an element (whose name is given in the targetElement argument). This function can take an optional third parameter (optionalTargetNamespace) that would be the namespace of the element.

ode:xml-to-json(xmlToConvert, targetElement, optionalTargetNamespace)

This function converts an XML string (specified by the xmlToConvert argument) into an element (whose name is given in the targetElement argument). This function can take an optional third parameter (optionalTargetNamespace) that would be the namespace of the element.

ode:dom-to-string(node)

This function serializes a DOM (Document Object Model) node, which is specified by the node argument, into a string.

String Functions

W3 Recommendation for XPath Version 2.0 String Functions.

string(object)

Converts an object to a string representation of the object. Converting an integer returns a string of equivalent numeric digits. Other numbers return a string with at least one digit before and after a decimal, and additional digits as required. A negative number is preceded by a minus sign (-). Special cases are handled as follows:

If the argument is omitted, the function converts a node-set with the context node as its only member.

codepoint-equal(comparand1, comparand2)

Compares two strings using the Unicode codepoint collation. Returns true or false depending on whether the value of comparand1 is equal to the value of comperand2.

codepoints-to-string(integer_sequence)

Converts a sequence of integers representing Unicode characters to the corresponding string. An error is thrown if any of the integers does not represent a valid XML character. The set of valid XML characters depends on whether XML 1.0 or 1.1 is the chosen version in the Configuration.

Example: fn:string-to-codepoints("Thérèse") returns the sequence (84, 104, 233, 114, 232, 115, 101).

compare(comparand1, comparand2)

Compares two strings using the default collation.

compare(comparand1, comparand2, collation)

Compares two strings using a specified collation.

concat(anyAtomicType_Arg1, anyAtomicType_Arg2, anyAtomicType_OptionalArgs)

Concatenates two or more strings to return a single string. There must be at least two arguments.

Example: concat("un,","grateful") returns "ungrateful".

contains(string, pattern)

Returns true if the second string is a substring of the first.

contains(string, pattern, collation)

Returns true if the second string is a substring of the first, under the rules of the chosen collation. This must correspond to a RuleBaseCollator.

encode-for-uri(uri)

Applies the %HH escaping convention to a URI, escaping both disallowed characters and reserved characters such as "/" and ":"

Example: concat("http://www.example.com/", encode-for-uri("100% organic")) returns "http://www.example.com/100%25%20organic".

ends-with(string, pattern)

Returns true if the first string ends with the second string.

ends-with(string, pattern, collation)

Returns true if the first string ends with the second string, when compared using the named collation. This must be a collation based on a RuleBasedCollator. See XPath 2.0 specification

escape-html-uri(uri)

Non-ASCII characters are escaped, but all ASCII characters, including spaces, are retained intact, in accordance with the HTML 4 specification.

This function is useful in conjunction with the serialization option escape-uri-attributes="no": it then allows escaping to be applied to URI-valued attributes selectively under application control.

Example: fn:escape-html-uri("http://www.example.com/00/Weather/CA/Los Angeles#ocean") returns "http://www.example.com/00/Weather/CA/Los Angeles#ocean".

iri-to-uri(iri)

Applies the %HH escaping convention to a URI, escaping only disallowed characters (but not reserved characters such as "/" and ":")

lower-case(string)

Changes characters in a string to lower case.

matches(input, pattern)

Returns true if the given string matches the given regular expression.

matches(input, pattern, flags)

Returns true if the given string matches the given regular expression, specifying flags to control the way pattern matching is performed.

normalize-space()

Returns a string equal to aString but stripped of leading and trailing white space, and with incidents of multiple adjacent white spaces replaced by a single space.

normalize-space(string)

Returns the whitespace-normalized value of the argument.

normalize-unicode(string)

Returns the normalized value of the first argument in the normalization form specified by the second argument.

normalize-unicode(string, normalizationForm)

Converts a string to a given Unicode normalized form by modifying the way in which combining characters are represented.

The normalization form must be one of NFC, NFD, NFKC, or NFKD. The value "fully-normalized" is not supported.

See the XPath 2.0 Specification for more information.

replace(input, pattern, replacement)

Replaces sequences of characters within a string that match a given regular expression.

replace(input, pattern, replacement, flags)

Replaces sequences of characters within a string that match a given regular expression, specifying flags to control the way the regular expression is matched.

starts-with(string, pattern)

Returns 'true' if aString starts with searchString; otherwise returns 'false'. Tests whether one estring starts with another string.

starts-with(string, pattern, collation)

Tests whether one string starts with another string, using the given collation for comparison.

string(item)

Returns the string value of the argument. The argument is implemented as type item()* rather than item()?

string-join(string_sequence, separator)

Concatenates all the strings in the given sequence, separated by the given separator.

string-length()

Returns the length of the argument.

string-length(string)

Returns the number of characters in a string.

string-to-codepoints(string)

Returns a sequence of integers that represent the Unicode codepoints of the characters in the supplied string.

Example: fn:string-to-codepoints("Thérèse") returns the sequence (84, 104, 233, 114, 232, 115, 101).

substring(aString, startPosition, optionalLength)

startPosition and optionalLength take numeric values. The first character in a string is at position 1. If optionalLength is not specified, substring returns the portion of aString from the character at startPosition to the end of the string. If optionalLength is specified, substring returns characters from startPosition to either optionalLength or the end of the string, whichever occurs first. Non-integer numeric values passed in either startPosition or optionalLength are rounded as if by a call to the round function.

Example: substring("123456", 3) returns "3456".

Example: substring("123456", 3, 2) returns "34".

Example: substring("123456", 3 div 2, 2.6) returns "234".

substring-after(aString, searchString)

Returns the portion of aString that follows the first occurrence of searchString. If aString does not contain searchString, substring-after returns an empty string.

Example: substring-after("1999/04/01","/") returns 04/01.

substring-before(aString, searchString)

Returns the portion of aString up to, but not including, the first occurrence of searchString. If aString does not contain searchString, substring-before returns an empty string.

Example: substring-before("1999/04/01","/") returns 1999.

tokenize(input, pattern)

Returns a sequence of strings formed by breaking the input string at any substring that matches the given regular expression.

tokenize(input, pattern, flags)

Returns a sequence of strings formed by breaking the input string at any substring that matches the given regular expression, using flags to control the way regular expression matching is performed.

translate(String, mapString, transString)

Finds occurrences in aString of characters from strOccur and replaces them with corresponding characters from strRepl. If strOccur is longer than strRepl, any character in strOccur without a corresponding character in strRepl will be removed from aString. If strRepl is longer than strOccur, additional characters are ignored.

Example: translate("it's ok","iok","IOK") returns: It's OK.

Example: translate("embiggen","bigem","BIG") returns: BIGgn.

upper-case(string)

Converts a string to upper case.

Operators

Operator Description Example
Arithmetic
+ Addition $aString + $bString
5 + 2 returns 7
- Subtraction 5 - 2 returns 3
* Multiplication 5 * 2 returns 10
div Division 5 div 2 returns 2.5
mod Modulus returns the remainder of a division operation. 5 mod 2 returns 1
12.5 mod 5 returns 2.5
Logical
and And x > 5 and x < 7 returns true if x = 6, otherwise returns false
or Or x > 7 or x < 5 returns false if x = 6, otherwise returns true
Relational
= Equal. (Note that = is not an assignment operator. A copy rule is used to assign value.) x=10 returns true if X equals 10, false otherwise
!= Not equal x!=10 returns false if X equals 10, false otherwise
< Less than x<10 returns true if X is less than 10, false otherwise
<= Less than or equal to x<=10 returns true if X is less than or equal to 10, false otherwise
> Greater than x>10 returns true if X is greater than 10, false otherwise
>= Greater than or equal to x>=10 returns true if X is greater than or equal to 10, false otherwise
Path
/ Forward slash - selects the root node /Cars/Car/Roadster selects Roadster elements within Car elements in the Cars.xml file
// Double forward slash - select all elements beneath the current node //Roadster selects all Roadster elements within the current context, regardless of their location
. Period - select the current node  
.. Double period - select the parent of the current node  
@ At sign - select attributes /Cars/Car/Roadster[./@Price>=30000] selects all Roadster elements that are beneath Car elements and whose price attribute is greater than or equal to 30000