Appendices > XSLT and XPath/XQuery Functions > Altova Extension Functions XPath/XQuery Functions: Sequence 
Scroll Home Prev Top Next More 
Altova's sequence extension functions can be used in XPath and XQuery expressions and provide additional functionality for the processing of data.
Note about naming of functions and language applicability
Altova extension functions can be used in XPath/XQuery expressions. They provide additional functionality to the functionality that is available in the standard library of XPath, XQuery, and XSLT functions. •In order to distinguish Altova extension functions from functions in the standard library, Altova extension functions are named in this documentation with a suffix of [altova:]. For example: addyearstodate [altova:]. •When using Altova extension functions in your XPath/XQuery expressions, however, you must use the function without any prefix or suffix, just as you would use any standard XPath/XQuery function. Use an Altova extension like this: addyearstodate(xs:date("20140115"), 10).

attributes(AttributeName as xs:string) as attribute()* XP3.1 XQ3.1 Returns all attributes that have a local name which is the same as the name supplied in the input argument, AttributeName. The search is casesensitive and conducted along the attribute:: axis. This means that the context node must be the parent element node.
attributes(AttributeName as xs:string, SearchOptions as xs:string) as attribute()* XP3.1 XQ3.1 Returns all attributes that have a local name which is the same as the name supplied in the input argument, AttributeName. The search is casesensitive and conducted along the attribute:: axis. The context node must be the parent element node. The second argument is a string containing option flags. Available flags are: p = includes the namespace prefix in the search; AttributeName should then contain the namespace prefix, for example: altova:MyAttribute.

elements(ElementName as xs:string) as element()* XP3.1 XQ3.1 Returns all elements that have a local name which is the same as the name supplied in the input argument, ElementName. The search is casesensitive and conducted along the child:: axis. The context node must be the parent node of the element/s being searched for.
elements(ElementName as xs:string, SearchOptions as xs:string) as element()* XP3.1 XQ3.1 Returns all elements that have a local name which is the same as the name supplied in the input argument, ElementName. The search is casesensitive and conducted along the child:: axis. The context node must be the parent node of the element/s being searched for. The second argument is a string containing option flags. Available flags are: p = includes the namespace prefix in the search; ElementName should then contain the namespace prefix, for example: altova:MyElement.

findfirst((Sequence as item()*), (Condition( SequenceItem as xs:boolean)) as item()? XP3.1 XQ3.1 This function takes two arguments. The first argument is a sequence of one or more items of any datatype. The second argument, Condition, is a reference to an XPath function that takes one argument (has an arity of 1) and returns a boolean. Each item of Sequence is submitted, in turn, to the function referenced in Condition. (Remember: This function takes a single argument.) The first Sequence item that causes the function in Condition to evaluate to true() is returned as the result of findfirst, and the iteration stops.

findfirstcombination((Seq01 as item()*), (Seq02 as item()*), (Condition( Seq01Item, Seq02Item as xs:boolean)) as item()* XP3.1 XQ3.1 This function takes three arguments:
•The first two arguments, Seq01 and Seq02, are sequences of one or more items of any datatype. •The third argument, Condition, is a reference to an XPath function that takes two arguments (has an arity of 2) and returns a boolean.
The items of Seq01 and Seq02 are passed in ordered pairs (one item from each sequence making up a pair) as the arguments of the function in Condition. The pairs are ordered as follows. If Seq01 = X1, X2, X3 ... Xn And Seq02 = Y1, Y2, Y3 ... Yn Then (X1 Y1), (X1 Y2), (X1 Y3) ... (X1 Yn), (X2 Y1), (X2 Y2) ... (Xn Yn)
The first ordered pair that causes the Condition function to evaluate to true() is returned as the result of findfirstcombination. Note that: (i) If the Condition function iterates through the submitted argument pairs and does not once evaluate to true(), then findfirstcombination returns No results; (ii) The result of findfirstcombination will always be a pair of items (of any datatype) or no item at all.

findfirstpair((Seq01 as item()*), (Seq02 as item()*), (Condition( Seq01Item, Seq02Item as xs:boolean)) as item()* XP3.1 XQ3.1 This function takes three arguments:
•The first two arguments, Seq01 and Seq02, are sequences of one or more items of any datatype. •The third argument, Condition, is a reference to an XPath function that takes two arguments (has an arity of 2) and returns a boolean.
The items of Seq01 and Seq02 are passed in ordered pairs as the arguments of the function in Condition. The pairs are ordered as follows. If Seq01 = X1, X2, X3 ... Xn And Seq02 = Y1, Y2, Y3 ... Yn Then (X1 Y1), (X2 Y2), (X3 Y3) ... (Xn Yn)
The first ordered pair that causes the Condition function to evaluate to true() is returned as the result of findfirstpair. Note that: (i) If the Condition function iterates through the submitted argument pairs and does not once evaluate to true(), then findfirstpair returns No results; (ii) The result of findfirstpair will always be a pair of items (of any datatype) or no item at all.

findfirstpairpos((Seq01 as item()*), (Seq02 as item()*), (Condition( Seq01Item, Seq02Item as xs:boolean)) as xs:integer XP3.1 XQ3.1 This function takes three arguments:
•The first two arguments, Seq01 and Seq02, are sequences of one or more items of any datatype. •The third argument, Condition, is a reference to an XPath function that takes two arguments (has an arity of 2) and returns a boolean.
The items of Seq01 and Seq02 are passed in ordered pairs as the arguments of the function in Condition. The pairs are ordered as follows. If Seq01 = X1, X2, X3 ... Xn And Seq02 = Y1, Y2, Y3 ... Yn Then (X1 Y1), (X2 Y2), (X3 Y3) ... (Xn Yn)
The index position of the first ordered pair that causes the Condition function to evaluate to true() is returned as the result of findfirstpairpos. Note that if the Condition function iterates through the submitted argument pairs and does not once evaluate to true(), then findfirstpairpos returns No results.

findfirstpos((Sequence as item()*), (Condition( SequenceItem as xs:boolean)) as xs:integer XP3.1 XQ3.1 This function takes two arguments. The first argument is a sequence of one or more items of any datatype. The second argument, Condition, is a reference to an XPath function that takes one argument (has an arity of 1) and returns a boolean. Each item of Sequence is submitted, in turn, to the function referenced in Condition. (Remember: This function takes a single argument.) The first Sequence item that causes the function in Condition to evaluate to true() has its index position in Sequence returned as the result of findfirstpos, and the iteration stops.

foreachattributepair(Seq1 as element()?, Seq2 as element()?, Function as function()) as item()* XP3.1 XQ3.1 The first two arguments identify two elements, the attributes of which are used to build attribute pairs, where one attribute of a pair is obtained from the first element and the other attribute is obtained from the second element. Attribute pairs are selected on the basis of having the same name, and the pairs are ordered alphabetically (on their names) into a set. If, for one attribute no corresponding attribute on the other element exists, then the pair is "disjoint", meaning that it consists of one member only. The function item (third argument Function) is applied separately to each pair in the sequence of pairs (joint and disjoint), resulting in an output that is a sequence of items.

foreachcombination(FirstSequence as item()*, SecondSequence as item()*, Function($i,$j){$i  $j} ) as item()* XP3.1 XQ3.1 The items of the two sequences in the first two arguments are combined so that each item of the first sequence is combined, in order, once with each item of the second sequence. The function given as the third argument is applied to each combination in the resulting sequence, resulting in an output that is a sequence of items (see example).

foreachmatchingattributepair(Seq1 as element()?, Seq2 as element()?, Function as function()) as item()* XP3.1 XQ3.1 The first two arguments identify two elements, the attributes of which are used to build attribute pairs, where one attribute of a pair is obtained from the first element and the other attribute is obtained from the second element. Attribute pairs are selected on the basis of having the same name, and the pairs are ordered alphabetically (on their names) into a set. If, for one attribute no corresponding attribute on the other element exists, then no pair is built. The function item (third argument Function) is applied separately to each pair in the sequence of pairs, resulting in an output that is a sequence of items.

substituteempty(FirstSequence as item()*, SecondSequence as item()) as item()* XP3.1 XQ3.1 If FirstSequence is empty, returns SecondSequence. If FirstSequence is not empty, returns FirstSequence.

© 20152021 Altova GmbH