15.1 Xalan, Saxon, and EXSLT Extensions

It would be overwhelming to list all available extensions from just these three sources. Thus, I have chosen to show a sampling of what's available from Xalan, Saxon, and EXSLT. Most processors offer their own documented extensions, but I will deal only with a handful of those offered by Saxon and EXSLT. Xalan offers only a few extension functions, so I'll show all those. The following tables list a number of extensions available from these sources.

Xalan C++ currently supports six internal extension functions, but it also has support for several EXSLT modules: common, math, set, and string (see http://xml.apache.org/xalan-c/extensionslib.html). Table 15-1 shows the extension functions that Xalan C++ offers directly.

Xalan Java provides a different set of extensions than Xalan C++, including a set of SQL extensions. See http://xml.apache.org/xalan-j/extensionslib.html for more information.


Table 15-1. Sample of Xalan C++ extension functions

Extension

Description

xalan:difference(node-set1, node-set2)

Returns a node-set from nodes that exist in one node-set but not in another.

xalan:distinct(node-set)

Returns a node-set that contains nodes with distinct string values.

xalan:evaluate(xpath-expression)

Evaluates an XPath expression supplied at runtime as a string.

xalan:hasSameNodes(node-set1, node-set2)

Returns true if the two node-sets contain exactly the same set of nodes.

xalan:intersection(node-set1, node-set2)

Returns a node-set from nodes that exist in two different node-sets.

xalan:nodeset(result-tree-fragment)

Returns a node-set from a result tree fragment defined in a variable.

The current release of Saxon at the time of this writing (7.7 or later) provides partial support for XSLT 2.0 plus a large number of extension attributes, elements, and functions (see http://saxon.sourceforge.net/ for more information). Other versions of Saxon, such as Instant Saxon 6.5.3, support only XSLT 1.0. As for EXSLT, Saxon supports the common, math, sets, dates/times, and functions modules. Some of Saxon's direct extensions are listed in Table 15-2.

Table 15-2. Sample of Saxon extensions

Extension

Type

Description

saxon:assignable

Attribute (variable element only)

Indicates whether a variable may have a new value assigned.

saxon:indent-spaces

Attribute (output or saxon:output element only)

Sets the number of indentation spaces used on the result tree.

saxon:assign

Element

Assigns a new value to an assignable variable.

saxon:output

Element

Outputs an additional result tree, saving it as a file.

saxon:while

Element

Iterates through a loop while a condition is true.

saxon:distinct(node-set-1, stored-expression?)

Function

Returns a node-set of nodes not duplicated in the optional stored-expression (current node list if not present).

saxon:evaluate(string)

Function

Evaluates an XPath expression.

saxon:has-same-nodes(node-set-1, node-set-2)

Function

Returns true if the two node-sets contain exactly the same set of nodes.

saxon:line-number( )

Function

Returns the line number of the current node in the source tree.

EXSLT currently proffers 74 extensions, most of them functions. Many of the functions offer a pure XSLT 1.0 solution using the call-template element that is using with-param children. Table 15-3 lists a single sample from each of the eight modules.

Table 15-3. Sample of EXSLT extensions

Extension

Module

Type

Description

date:date( )

Date and time

Function

Returns the current date.

dyn:evaluate(string)

Dynamic

Function

Evaluates an XPath expression.

exsl:node-set(object)

Common

Function

Returns a node-set from a result tree fragment defined in a variable.

func:function

Functions

Element

Declares an extension function.

math:lowest(node-set)

Math

Function

Returns the lowest value from a node-set.

regexp:test(string, string, string?)

Regular expressions

Function

Returns true if the string in the first argument matches the regular expression in the second argument (the third argument is an optional flag).

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

Sets

Function

Returns a node-set from nodes that exist in one node-set but not in another.

str:tokenize(string, string?)

Strings

Function

Breaks a string into tokens (the second argument is an optional delimiter).

Although these tables list only a sample of what's available, you may have noticed that there are some extensions that are implemented by more than one processor the distinct( ) extension function, for example, is supported by both Xalan and Saxon. In XSLT 2.0, this extension function has evolved into the fn:distinct-values( ) function. You can learn more about these functions in the W3C specification for XPath 2.0 (and XQuery 1.0) functions and operators at http://www.w3.org/TR/xpath-functions/. You will also get an introduction to XSLT 2.0 and XPath 2.0 in Chapter 16.



Learning XSLT
Learning XSLT
ISBN: 0596003277
EAN: 2147483647
Year: 2003
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net