XSLT Functions

www.altova.com Expand/Collapse All Print this Topic Previous Page Up One Level Next page

Home >  Engine Information > XSLT and XPath/XQuery Functions > Altova Extension Functions >

XSLT Functions

XSLT extension functions can be used in XPath expressions in an XSLT context. They will not work in a non-XSLT context (for instance, in an XQuery context).


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. Altova extension functions are in the Altova extension functions namespace, http://www.altova.com/xslt-extensions, and are indicated in this section with the prefix altova:, which is assumed to be bound to this namespace. Note that, in future versions of your product, support for a function might be discontinued or the behavior of individual functions might change. Consult the documentation of future releases for information about support for Altova extension functions in that release.


XPath functions (used in XPath expressions in XSLT):

XP1 XP2 XP3.1

XSLT functions (used in XPath expressions in XSLT):


XQuery functions (used in XQuery expressions in XQuery):

XQ1 XQ3.1


Standard functions

Click to expand/collapsedistinct-nodes [altova:]

altova:distinct-nodes(node()*) as node()*     Xslt1 XSLT2 XSLT3

Takes a set of one or more nodes as its input and returns the same set minus nodes with duplicate values. The comparison is done using the XPath/XQuery function fn:deep-equal.

altova:distinct-nodes(country) returns all child country nodes less those having duplicate values.



Click to expand/collapseevaluate [altova:]

altova:evaluate(XPathExpression as xs:string[, ValueOf$p1, ... ValueOf$pN])     Xslt1 XSLT2 XSLT3

Takes an XPath expression, passed as a string, as its mandatory argument. It returns the output of the evaluated expression. For example: altova:evaluate('//Name[1]') returns the contents of the first Name element in the document. Note that the expression //Name[1] is passed as a string by enclosing it in single quotes.


The altova:evaluate function can optionally take additional arguments. These arguments are the values of in-scope variables that have the names p1, p2, p3... pN. Note the following points about usage: (i) The variables must be defined with names of the form pX, where X is an integer; (ii) the altova:evaluate function's arguments (see signature above), from the second argument onwards, provide the values of the variables, with the sequence of the arguments corresponding to the numerically ordered sequence of variables: p1 to pN: The second argument will be the value of the variable p1, the third argument that of the variable p2, and so on; (iii) The variable values must be of type item*.


<xsl:variable name="xpath" select="'$p3, $p2, $p1'" />

<xsl:value-of select="altova:evaluate($xpath, 10, 20, 'hi')" />

outputs "hi 20 10"


In the listing above, notice the following:


The second argument of the altova:evaluate expression is the value assigned to the variable $p1, the third argument that assigned to the variable $p2, and so on.
Notice that the fourth argument of the function is a string value, indicated by its being enclosed in quotes.
The select attribute of the xs:variable element supplies the XPath expression. Since this expression must be of type xs:string, it is enclosed in single quotes.



<xsl:variable name="xpath" select="'$p1'" />
<xsl:value-of select="altova:evaluate($xpath, //Name[1])" />
Outputs value of the first Name element.
<xsl:variable name="xpath" select="'$p1'" />
<xsl:value-of select="altova:evaluate($xpath, '//Name[1]')" />
Outputs "//Name[1]"


The altova:evaluate() extension function is useful in situations where an XPath expression in the XSLT stylesheet contains one or more parts that must be evaluated dynamically. For example, consider a situation in which a user enters his request for the sorting criterion and this criterion is stored in the attribute UserReq/@sortkey. In the stylesheet, you could then have the expression: <xsl:sort select="altova:evaluate(../UserReq/@sortkey)" order="ascending"/>. The altova:evaluate() function reads the sortkey attribute of the UserReq child element of the parent of the context node. Say the value of the sortkey attribute is Price, then Price is returned by the altova:evaluate() function and becomes the value of the select attribute: <xsl:sort select="Price" order="ascending"/>. If this sort instruction occurs within the context of an element called Order, then the Order elements will be sorted according to the values of their Price children. Alternatively, if the value of @sortkey were, say, Date, then the Order elements would be sorted according to the values of their Date children. So the sort criterion for Order is selected from the sortkey attribute at runtime. This could not have been achieved with an expression like: <xsl:sort select="../UserReq/@sortkey" order="ascending"/>. In the case shown above, the sort criterion would be the sortkey attribute itself, not Price or Date (or any other current content of sortkey).


Note:The static context includes namespaces, types, and functionsbut not variablesfrom the calling environment. The base URI and default namespace are inherited.


Static variables: <xsl:value-of select="$i3, $i2, $i1" />
Outputs the values of three variables.
Dynamic XPath expression with dynamic variables:
<xsl:variable name="xpath" select="'$p3, $p2, $p1'" />
<xsl:value-of select="altova:evaluate($xpath, 10, 20, 30)" />
Outputs "30 20 10"
Dynamic XPath expression with no dynamic variable:
<xsl:variable name="xpath" select="'$p3, $p2, $p1'" />
<xsl:value-of select="altova:evaluate($xpath)" />
Outputs error: No variable defined for $p3.



Click to expand/collapseencode-for-rtf [altova:]

altova:encode-for-rtf(input as xs:stringpreserveallwhitespace as xs:booleanpreservenewlines as xs:boolean) as xs:string     XSLT2 XSLT3

Converts the input string into code for RTF. Whitespace and new lines will be preserved according to the boolean value specified for their respective arguments.



[ Top ]


XBRL functions

Altova XBRL functions can be used only with editions of Altova products that have XBRL support.


Click to expand/collapsexbrl-footnotes [altova:]

altova:xbrl-footnotes(node()) as node()*     XSLT2 XSLT3

Takes a node as its input argument and returns the set of XBRL footnote nodes referenced by the input node.



Click to expand/collapsexbrl-labels [altova:]

altova:xbrl-labels(xs:QNamexs:string) as node()*     XSLT2 XSLT3

Takes two input arguments: a node name and the taxonomy file location containing the node. The function returns the XBRL label nodes associated with the input node.




[ Top ]


© 2019 Altova GmbH