xslt | xpath functions

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Functions > Function Library Reference >

xslt | xpath functions

The functions in the XPath Functions library are XPath 1.0 nodeset functions. Each of these functions takes a node or nodeset as its context and returns information about that node or nodeset. These function typically have:

 

a context node (in the screenshot below, the context node for the lang function is the Language element of the source schema).
an input argument (in the screenshot below, the input argument for the lang function is the string constant en). The last and position functions take no argument.

FXxpath10

 

lang

The lang function takes a string argument that identifies a language code (such as en). The function returns true or false depending on whether the context node has an xml:lang attribute with a value that matches the argument of the function. In the screenshot above notice the following:

 

1.In the source schema, the Language element has an xml:lang attribute.
2.Language nodes are filtered so that only those Language nodes having an xml:lang value of en are processed (the filter test is specified in the equal function).
3.The Language node is the context node at the point where the en element is created in the output document.
4.The output of the lang function (true or false) is sent to the en/@exists attribute node of the output. The argument of the function is provided by the string constant en. The lang function then checks whether the context node at this point (the Language element) has an xml:lang attribute with a value of en (the argument of the function). If yes, then true is returned, otherwise false.

 

last, position

The last and position functions take no argument. The last function returns the position of the last node in the context nodeset. The position function returns the position of the current node in the nodeset being processed.

 

The context nodeset at the nodes where the functions are directed is the nodeset to which the functions will apply. In the screenshot below, the nodeset of Language elements is the context nodeset for the last and position functions.

FXxpath10last

In the example above, the last function returns the position of the last node of the context nodeset (the nodeset of Language elements) as the value of the number attribute. This value is also the size of the nodeset since it indicates the number of nodes in the nodeset.

 

The position function returns the position of the Language node being currently processed. For each Language element node, its position within the nodeset of Language elements is output to the language/@position attribute node.

 

name, local-name, namespace-uri

These functions are all used the same way and return, respectively, the name, local-name, and namespace URI of the input node. The screenshot below shows how these functions are used. Notice that no context node is specified.

 

The name function returns the name of the Language node and outputs it to the language/@elementname attribute. If the argument of any of these functions is a nodeset instead of a single node, the name (or local-name or namespace URI) of the first node in the nodeset is returned.

FXxpath10name

The name function returns the QName of the node; the local-name function returns the local-name part of the node's QName. For example, if a node's QName is altova:MyNode, then MyNode is the local name.

 

The namespace URI is the URI of the namespace to which the node belongs. For example, the altova: prefix can be declared to map to a namespace URI in this way: xmlns:altova="http://www.altova.com/namespaces".

 

Note:Additional XPath 1.0 functions can be found in the Core function library.

© 2019 Altova GmbH