Skip to main content

XML for Data: Extend XSLT's functionality with EXSLT

A look at the EXSLT standard and how it extends the functionality of XSLT 1.0

Kevin Williams (kevin@blueoxide.com), CTO, Blue Oxide Technologies, LLC
Kevin Williams is the CTO of Blue Oxide Technologies, LLC, a company that designs software tools that help companies take advantage of the service-oriented Internet. Visit their Web site at http://www.blueoxide.com. He can be reached for comment at kevin@blueoxide.com.

Summary:  This column provides a quick overview of the EXSLT standardized extensions to XSLT 1.0. It identifies some of the more important functionality provided by the EXSLT extensions, and includes some guidelines as to their use.

View more content in this series

Date:  01 Dec 2002
Level:  Introductory
Activity:  2140 views

As seen over the past couple of columns, XSLT 1.0 provides good text transformation functionality, but doesn't really go far enough to provide good data manipulation capabilities. To be fair, it was never intended to do so; as XSLT 1.0 was being designed, its creators couldn't have known the convoluted uses it would be put to. However, the XSLT 1.0 specification does provide a mechanism for extending the functionality of XSLT through additional elements and functions. The relevant passages from the specification are these:

The element extension mechanism allows namespaces to be designated as extension namespaces. When a namespace is designated as an extension namespace and an element with a name from that namespace occurs in a template, then the element is treated as an instruction rather than as a literal result element. The namespace determines the semantics of the instruction.
If a FunctionName in a FunctionCall expression is not an NCName (i.e. if it contains a colon), then it is treated as a call to an extension function. The FunctionName is expanded to a name using the namespace declarations from the evaluation context.

This means that if XSLT processor developers want to add more functionality, they are free to do so -- as long as the elements and function names that support that functionality appear in their own namespace. One of the first major efforts to take advantage of this feature was Mike Kay's Saxon XSLT processor: By including elements and attributes from the saxon: namespace, developers could create style sheets that performed complex manipulation of source documents. The downside was that the style sheets were no longer portable: They did not function correctly in non-Saxon processors. Similarly, some Java implementations of XSLT extended the functionality by allowing Java calls directly from style sheets using the java: namespace -- but on processors that did not support elements and attributes from this namespace, the style sheets did not work correctly.

What is EXSLT?

To make XSLT extensions more portable, a group of developers have created the EXSLT specification. This is an attempt to identify useful extensions to XSLT 1.0 and to partition them into functional groups that can be implemented on an á la carte basis. The EXSLT effort is an open one; anyone who wishes to contribute may do so.

The modules currently defined for EXSLT are:

  • Dates and Times provides a broad spectrum of date manipulation functionality, including calculating the difference between two dates and retrieving the local system current date and time.
  • Dynamic provides a mechanism for the processing of dynamically-generated XPath expressions to accomplish various tasks, including retrieving values and selecting minimum and maximum values.
  • Common provides a few basic extension functions, such as a mechanism for the creation of multiple output files and a function that returns a string containing the object type of an object passed into it.
  • Functions provides a mechanism for users to define their own functions.
  • Math provides simple math functions, such as trigonometric functions and logarithmic functions.
  • Regular Expressions provides regular expression processing functionality, including a function that selects substrings of a string that match a given regular expression and a function that replaces matching substrings with a different literal value.
  • Sets provides functions for nodeset manipulation, including returning the intersection of two nodesets and returning nodes that appear in one nodeset but not another.
  • Strings provides some very useful string manipulation functions, such as a function that tokenizes a string into a nodeset of token elements and a function that concatenates the string values of all the nodes in a nodeset.

Using EXSLT

Because EXSLT hasn't been formally accepted by any standards bodies, implementation of the functionality in EXSLT tends to be hit-and-miss. There are several different ways these functions may be implemented, listed here in increasing order of portability:

XSLT templates. Many of the functions in EXSLT are simply shortcuts to equivalent behaviors that can be achieved using XSLT templates. For these functions, the EXSLT authors have provided XSLT templates that may be imported into existing style sheets. This approach offers the most portability, as all XSLT 1.0-compliant processors are able to correctly interpret the template and provide the functionality.

EXSLT functions. If the XSLT processor you are using supports the function element from the function namespace in XSLT, you can take advantage of the EXSLT function implementations that are provided for some functions. This approach is a little less portable than XSLT templates, but you can use the function as part of other expressions in your style sheets.

Language-specific implementations. For some functions that are simple enough to be implemented in languages like JavaScript, implementations are available that you can include in processors that support those languages. Functions such as the ones in the math namespace are ideal for this.

Native implementations by specific processors. The most functionality can be offered by processors that include native support for EXSLT functions. Some EXSLT functions, such as those in the dynamic namespace, can only be implemented natively.

Depending on which functions you need to use and the amount of portability that your style sheets require, any of these solutions might be the best fit for your needs. You can find full documentation on the implementation status of each function or element in EXSLT at the EXSLT Web site.


So is EXSLT a good idea for you?

As usual, whether EXSLT is right for a particular programming task really depends on your particular circumstances. If you are writing style sheets that may be locked into a particular processor platform (such as style sheets used to transform documents on a server), then you may be able to select a processor that implements the extension functions and elements you need. If you need portable style sheets (for client-side styling, for example, or in a multiple XSLT processor environment), then you may need to limit your use of XSLT to those functions that you can implement with XSLT templates. The good news is that XSLT 2.0 contains many functions and elements that are similar, or identical, to those found in EXSLT -- so if you invest in EXSLT implementations now, porting them to XSLT 2.0 should be a relatively simple task. You could even use a style sheet to transform EXSLT style sheets into XSLT 2.0 style sheets -- but that's another column.


Resources

About the author

Kevin Williams is the CTO of Blue Oxide Technologies, LLC, a company that designs software tools that help companies take advantage of the service-oriented Internet. Visit their Web site at http://www.blueoxide.com. He can be reached for comment at kevin@blueoxide.com.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=12194
ArticleTitle=XML for Data: Extend XSLT's functionality with EXSLT
publish-date=12012002
author1-email=kevin@blueoxide.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers