## XPath Function - II

These are functions that are offered as an extension of the above listed functions in different sources or they are unique to the CLaRK system. The first source is the book: XPath and XPointer by John E. Simpson, Appendix A: Extension Functions for XPath in XSLT (EXSLT functions).

### 1.EXSLT Math Functions:

> - math:min(node-set) : number

>   The math:min function returns the minimum value of the nodes passed as the argument. The minimum value is defined as follows. The node set passed as an argument is sorted in ascending order as it would be by xsl:sort with a data type of number. The minimum is the result of converting the string value of the first node in this sorted list to a number using the number function. If the node set is empty, or if the result of converting the string values of any of the nodes to a number is NaN, then NaN is returned.

> - math:max(node-set) : number

>   The math:max function returns the maximum value of the nodes passed as the argument. The maximum value is defined as follows. The node set passed as an argument is sorted in descending order as it would be by xsl:sort with a data type of number. The maximum is the result of converting the string value of the first node in this sorted list to a number using the number function. If the node set is empty, or if the result of converting the string values of any of the nodes to a number is NaN, then NaN is returned.

> - math:highest(node-set) : node-set

>   The math:highest function returns the nodes in the node set whose value is the maximum value for the node set. The maximum value for the node set is the same as the value as calculated by math:max. A node has this maximum value if the result of converting its string value to a number as if by the number function is equal to the maximum value, where the equality comparison is defined as a numerical comparison using the = operator. If any of the nodes in the node set has a non-numeric value, the math:max function will return NaN. The definition numeric comparisons entails that NaN != NaN. Therefore if any of the nodes in the node set has a non-numeric value, math:highest will return an empty node set.

> - math:lowest(node-set) : node-set

>   The math:lowest function returns the nodes in the node set whose value is the minimum value for the node set. The minimum value for the node set is the same as the value as calculated by math:min. A node has this minimum value if the result of converting its string value to a number as if by the number function is equal to the minimum value, where the equality comparison is defined as a numerical comparison using the = operator. If any of the nodes in the node set has a non-numeric value, the math:min function will return NaN. The definition numeric comparisons entails that NaN != NaN. Therefore if any of the nodes in the node set has a non-numeric value, math:lowest will return an empty node set.

> - math:abs(number) : number

>   The math:abs function returns a number containg the absolute value of the number passed as an argument.

> - math:sqrt(number) : number

>   The math:sqrt function returns the square root of a number. If the argument is a negative number, the return value is zero.

> - math:power(number,number) : number

>   The math:power function returns the value of a base expression taken to a specified power.

> - math:log(number) : number

>   The math:log function returns the natural logarithm of a number. The return value is the natural logarithm of number. The base is e.

> - math:random() : number

>   The math:random function returns a random number from 0 to 1.

> - math:sin(number) : number

>   The math:sin function returns the sine of the number in radians.

> - math:cos(number) : number

>   The math:cos function returns cosine of the passed argument in radians.

> - math:tan(number) : number

>   The math:tan function returns the tangent of the number passed as an argument in radians.

> - math:asin(number) : number

>   The math:asin function returns the arcsine value of a number in radians.

> - math:acos(number) : number

>   The math:acos function returns the arccosine value of a number in radians.

> .
> - math:atan(number) : number

>   The math:atan function returns the arctangent value of a number in radians.

> - math:atan2(number, number) : number

>   The math:atan2 function returns the angle ( in radians ) from the X axis to a point (y,x). Value1 is a number argument cooresponding to y of point (y,x). Value2 is a number argument cooresponding to x of point (y,x). second.

> - math:exp(number) : number

>   The math:exp function returns e (the base of natural logarithms) raised to a power.

### 2.EXSLT Sets Functions:

> - set:difference(node-set,node-set) : node-set

>   The set:difference function returns the difference between two node sets - those nodes that are in the node set passed as the first argument that are not in the node set passed as the second argument.

> - set:intersection(node-set,node-set) : node-set

>   The set:intersection function returns a node set comprising the nodes that are within both the node sets passed as arguments to it.

> - set:distinct(node-set) : node-set

>   The set:distinct function returns a node-set containg a subset of nodes for which each two nodes, compared with the eq() function the result is false, i.e. it returns a subset of all nodes which have unique substructures.

> - set:has-same-node(node-set,node-set) : boolean

>   The set:has-same-node function returns true if the node set passed as the first argument shares any nodes with the node set passed as the second argument. If there are no nodes that are in both node sets, then it returns false.

> - set:leading(node-set,node-set) : node-set

>   The set:leading function returns the nodes in the node set passed as the first argument that precede, in document order, the first node in the node set passed as the second argument. If the first node in the second node set is not contained in the first node set, then an empty node set is returned. If the second node set is empty, then the first node set is returned.

> - set:trailing(node-set,node-set) : node-set

>   The set:trailing function returns the nodes in the node set passed as the first argument that follow, in document order, the first node in the node set passed as the second argument. If the first node in the second node set is not contained in the first node set, then an empty node set is returned. If the second node set is empty, then the first node set is returned.

> - set:generate-id(node-set) : string

>   The set:generate-id function returns an unique string identifier for the first member node of the argument. The identifier is based on the position of the node in the tree. The result is an empty string if the argument set is empty or the first node is an attribute node.

> - set:eq(object, object) : boolean

>   The set:eq function compares two objects which are expected to be ordered node-sets. If an argument is not of type node-set, this function compares the two arguments in the way they are compared by the "=" operator. The nodes in the two sets are compared positionally (first with first, second with second, and so on). Two nodes are equal if:

>   - they are of the same type (element, text, attribute);
>   - they are text nodes and their content character sequences are the same;
>   - they are attribute nodes which have same names and same values;
>   - they are element nodes which:
>     1. have the same names;
>     2. each attribute from the first node has a corresponding equal attribute in the second node and vice versa;
>     3. have the same number of children and each two children which have equal positions in their parent nodes are recursively equal;
>   In all other cases the nodes are different.
> - set:order(node-set) : node-set

>   The set:order function receives an arbitrary set of nodes and produces a new set with the same nodes ordered in document order. If the input set contains attributes, their position in the document order is the same as the element nodes they belong to. As attributes within an element node do not have an ordering defined, the way they appear in the result set is undetermined. But for sure they will appear in the positions where their corresponding element nodes would appear.

> - set:reverse(node-set) : node-set

>   The set:order function receives an arbitrary set of nodes and produces a new set with the same nodes ordered in reverse document order. If the input set contains attributes, their position in the document order is the same as the element nodes they belong to. As attributes within an element node do not have an ordering defined, the way they appear in the result set is undetermined. But for sure they will appear in the positions where their corresponding element nodes would appear.

### 3.EXSLT String Functions:

> - str:align(string, string, string?) : string

>   The str:align function aligns a string within another string. The first argument gives the target string to be aligned. The second argument gives the padding string within which it is to be aligned. If the target string is shorter than the padding string then a range of characters in the padding string are repaced with those in the target string. Which characters are replaced depends on the value of the third argument, which gives the type of alignment. It can be one of 'left', 'right' or 'center'. If no third argument is given or if it is not one of these values, then it defaults to left alignment. With left alignment, the range of characters replaced by the target string begins with the first character in the padding string. With right alignment, the range of characters replaced by the target string ends with the last character in the padding string. With center alignment, the range of characters replaced by the target string is in the middle of the padding string, such that either the number of unreplaced characters on either side of the range is the same or there is one less on the left than there is on the right. If the target string is longer than the padding string, then it is truncated to be the same length as the padding string and returned.

> - str:concat(node-set) : string

>   The str:concat function takes a node set and returns the concatenation of the string values of the nodes in that node set. If the node set is empty, it returns an empty string.

> - str:padding(number, string?) : string

>   The str:padding function creates a padding string of a certain length. The first argument gives the length of the padding string to be created. The second argument gives a string to be used to create the padding. This string is repeated as many times as is necessary to create a string of the length specified by the first argument; if the string is more than a character long, it may have to be truncated to produce the required length. If no second argument is specified, it defaults to a space (' '). If the second argument is an empty string, str:padding returns an empty string.

> - str:index-of(string, string, number?) : number

>   The str:index-of function returns the starting position of the first occurance of the second string argument within the content of the first argument. If a third argument is presented then the searching in the first argument starts from the specified position. If the first argument does not contain the second one (after a certain position if specified) then the result is -1.

> - str:last-index-of(string, string, number?) : number

>   The str:last-index-of function returns the starting position of the last occurance of the second string argument within the content of the first argument. If a third argument is presented then the function returns the last occurance before the specified position. If the first argument does not contain the second one the result is -1.

> - str:region-matches(string, number, string, number, number, boolean) : boolean

>   Tests if two string regions are equal. A substring of the first string argument, starting at position - second agrument, is compared to a substring of the third argument, starting at position - fourth argument with length - fifth argument. The result is true if these substrings represent character sequences that are the same, ignoring case if and only if the sixth argument is true. The result is false if one of the following is true:

>   - second argument is negative;
>   - fourth argument is negative;
>   - the sum of the second argument and the sixth argument is greater than the length of first argument;
>   - the sum of the fourth argument and the sixth argument is greater than the length of third argument;
>   Example: region-matches("abcdef", 2, "ECDF", 1, 2, true) --> true
> - str:to-lower-case(string) : string

>   Converts all of the characters in the string argument to lower case using the rules of the current environment.

> - str:to-upper-case(string) : string

>   Converts all of the characters in the string argument to upper case using the rules of the current environment.

> - ends-with(string, string) : boolean

>   Tests if the first argument ends with the specified suffix as second argument. The result is true if the character sequence represented by the second argument is a suffix of the character sequence represented by the first argument. Otherwise it is false.

> - str:count-tokens(string, string) : number

>   Returns the number of the tokens in the first string argument. The token boundaries are stated in the second argument. Example: str:count-tokens("one two three", " ") --> 3

> - str:token-at(string, string, number) : string

>   Returns a token from the first string argument at position specified in the third argument. The second argument represents the separator between the tokens.

> - clark:count-tokens( string, string, string? ) : number

>   Returns the number of the tokens in the first string argument. This function is CLaRK System specific: the second argument is a tokenizer name and the third one is a filter name (optional).

> - clark:token-at(string, number, string, string?) : string

>   Returns a token from the first string argument at position specified in the second argument.This function is CLaRK System specific: the third argument is a tokenizer name and the fourth one is a filter name (optional).