1. Extension functions

node-set copy(node-set)

Returns a deep copy of specified node set.

object defined(string variable-name, default-value?)

When passed a single argument, returns true() if a variable having specified name is defined; returns false() otherwise.

When passed two arguments, returns the value of the variable having specified name if this variable is defined; returns default-value otherwise.

variable-name must have one of the following forms: prefix:local_part, where prefix has been defined in the document being edited, or {namespace_URI}local_part.

node-set difference(node-set1, node-set2)

Returns a node-set containing all nodes found in node-set1 but not in node-set2.

boolean ends-with(string1, string2)

Returns true if string string1 ends with string string2. Returns false otherwise.

number index-of-node(node-set1, node-set2)

Returns the rank of a node in node-set1. The node which is searched in node-set1 is specified using node-set2: it is first node in node-set2 (which generally contains a single node). The index of first node in node-set1 is 1 and not 0. Returns -1 if the searched node is not found in node-set1.

object if(boolean test1, object value1, ..., boolean testN, object valueN, ...., object fallback)

Evaluates each testi in turn as a boolean. If the result of evaluating testi is true, returns corresponding valuei. Otherwise, if all testi evaluate to false, returns fallback.

Example:

if(@x=1,"One",@x=2,"Two",@x=3,"Three","Other than one two three")
node-set intersection(node-set1, node-set2)

Returns a node-set containing all nodes found in both node-set1 and node-set2.

boolean is-editable(node-set?)

Returns true() if first node of specified node set is editable; returns false() otherwise. When node-set is not specified, this function is applied to the context node.

Also returns true() if specified node set is empty.

is-editable() is a convenient alternative to:

not(ancestor-or-self::*[¬
  property('{http://www.xmlmind.com/xmleditor/namespace/property}readOnly')])

See property().

string join(node-set node-set, string separator)

Converts each node in node-set to a string and joins all these strings using separator. Returns the resulting string.

Example: join(//h1, ', ') returns "Introduction, Conclusion" if the document contains 2 h1 elements, one containing "Introduction" and the other "Conclusion".

string lower-case(string)

Returns the value of its argument after translating every character to its lower-case correspondent as defined in the appropriate case mappings section in the Unicode standard.

boolean matches(string input, string pattern, string flags?)

Similar to XPath 2.0 function matches. Returns true if input matches the regular expression pattern; otherwise, it returns false.

Note that unless ^ and $ are used, the string is considered to match the pattern if any substring matches the pattern.

Optional flags may be used to parametrize the behavior of the regular expression:

m

Operate in multi-line mode. In multi-line mode, the expressions ^ and $ match just after or just before, respectively, a line terminator or the end of the input sequence. By default, these expressions only match at the beginning and the end of the entire input sequence.

s

Operate in single line mode. In single line mode, the expression . matches any character, including a line terminator. By default, this expression does not match line terminators.

i

Operate in case-insensitive mode (in a manner consistent with the Unicode Standard).

l

Treat the pattern as a sequence of literal characters.

Regular expression reference: java.util.regex.Pattern.

Examples: matches("foobar", "^f.+r$") returns true. matches("CamelCase", "ca", "i") returns true.

number max(node-set), number max(number, ..., number)

The first form returns the maximum value of all nodes of specified node set, after converting each node to a number.

Nodes which cannot be converted to a number are ignored. If all nodes cannot be converted to a number, returns NaN.

The second form returns the maximum value of all specified numbers (at least 2 numbers).

Arguments which cannot be converted to a number are ignored. If all arguments cannot be converted to a number, returns NaN.

number min(node-set), number min(number, ..., number)

Same as max() but returns the minimum value of specified arguments.

number pow(number1, number2)

Returns number1 raised to the power of number2.

string property(string property-name, node-set?)

Returns the application-level property having specified name attached to first node of specified node set. When node-set is not specified, this function is applied to the context node.

Returns the empty string if the specified node set is empty or if the first node in the node set does not have specified property.

property-name must have one of the following forms: prefix:local_part, where prefix has been defined in the document being edited, or {namespace_URI}local_part. Examples:

  • foo,

  • bar:foo, where prefix bar is bound to "http://www.bar.com/ns" in the document being edited,

  • {}foo,

  • {http://www.xmlmind.com/xmleditor/namespace/property}sourceURL,

  • {http://www.xmlmind.com/xmleditor/namespace/property}readOnly,

  • {http://www.xmlmind.com/xmleditor/namespace/property}configurationName.

See also is-editable().

string replace(string input, string pattern, string replacement, string flags?)

Similar to XPath 2.0 function replace. Returns the string that is obtained by replacing all non-overlapping substrings of input that match the given pattern with an occurrence of the replacement string.

The replacement string may use $1 to $9 to refer to captured groups.

Optional flags may be used to parametrize the behavior of the regular expression:

m

Operate in multi-line mode. In multi-line mode, the expressions ^ and $ match just after or just before, respectively, a line terminator or the end of the input sequence. By default, these expressions only match at the beginning and the end of the entire input sequence.

s

Operate in single line mode. In single line mode, the expression . matches any character, including a line terminator. By default, this expression does not match line terminators.

i

Operate in case-insensitive mode (in a manner consistent with the Unicode Standard).

l

Treat the pattern as a sequence of literal characters.

Example: replace("foobargeebar", "b(.+)r", "B$1R") returns "fooBaRgeeBaR".

string resolve-uri(string uri, string base?)

If uri is an absolute URL, returns uri.

If base is specified, it must be a valid absolute URL, otherwise an error is reported.

If uri is a relative URL,

  • if base is specified, returns uri resolved using base;

  • if base is not specified, returns uri resolved using the base URL of the context node.

If uri is the empty string,

  • if base is specified, returns base;

  • if base is not specified, returns the base URL of the context node.

string relativize-uri(string uri, string base?)

Converts absolute URL uri to an URL which is relative to specified base URL base. If base is not specified, the base URL of the context node is used instead.

Uri must be a valid absolute URL, otherwise an error is reported. If base is specified, it must be a valid absolute URL, otherwise an error is reported.

Example: returns "../john/.profile" for uri="file:///home/john/.profile" and base="file:///home/bob/.cshrc".

If uri cannot be made relative to base (example: uri="file:///home/john/public_html/index.html" and base="http://www.xmlmind.com/index.html"), uri is returned as is.

string serialize(node-set)

Serializes specified node-set and returns a well-formed, parseable, XML string. This string is not nicely indented. This string always starts with <?xml version="1.0"?> as it is intended to be directly consumed by other commands such as paste.

If multiple nodes are to be serialized (as opposed to a single element node or to a document node), these nodes are first wrapped in a {http://www.xmlmind.com/xmleditor/namespace/clipboard}clipboard element.

Note that some node-sets cannot be serialized: the empty node-set, node-sets containing just attribute nodes, node-sets mixing a document node with other kind of nodes, etc. In such cases, an error is reported.

node-set tokenize(string input, string pattern, string flags?)

Similar to XPath 2.0 function tokenize, except that it returns a node-set comprising text nodes rather than a sequence of strings.

This function breaks the input string into a sequence of strings, treating any substring that matches pattern as a separator. The separators themselves are not returned. If input is the zero-length string, the result is an empty node-set.

Optional flags may be used to parametrize the behavior of the regular expression:

m

Operate in multiline mode.

i

Operate in case-insensitive mode.

Examples: tokenize("abracadabra", "(ab)|(a)") returns a node-set containing 6 text nodes. The string values of these text nodes are "", "r", "c", "d", "r", "". tokenize("ABRACADABRA", "(ab)|(a)", "i") returns a node-set containing 6 text nodes. The string values of these text nodes are "", "R", "C", "D", "R", "".

string upper-case(string)

Returns the value of its argument after translating every character to its upper-case correspondent as defined in the appropriate case mappings section in the Unicode standard.

string uri-or-file-name(string)

Converts specified string to an URL. Specified string may be an (absolute) URL supported by XMLmind XML Editor or the absolute or relative filename of a file or of a directory. An error is reported if the argument cannot be converted to an URL.

string uri-to-file-name(string)

Converts specified argument, a "file://" URL, to a native file name. Returns the empty string if argument is not a "file://" URL.