XSLT Standard Library

Version 1.2.1

Steve Ball


Table of Contents

1. Using The Library
2. Obtaining The Library
3. Getting Involved
4. XML Namespaces
5. Engineering Standards
6. Related Work
7. Reference Documentation
String Processing
Nodes
Date/Time Processing
Mathematics
URI (Uniform Resource Identifier) Processing
Comparing Nodesets
Generating XML Markup
Presentation Media Support
Example

The XSLT Standard Library, xsltsl, provides the XSLT developer with a set of XSLT templates for commonly used functions. These are implemented purely in XSLT, that is they do not use any extensions.

xsltsl is a SourceForge project.

SourceForge Logo

Goals of the xsltsl project include:

  • Provision of a high-quality library of XSLT templates, suitable for inclusion by vendors in XSLT processor software products.

  • Demonstration of best practice in XSLT stylesheet development and documentation.

  • Provide examples of various techniques used to develop XSLT stylesheets (ie. a working FAQ).

Chapter 1. Using The Library

There are two ways of using the library:

  • Use a local copy of the library.

    1. Download the distribution (see below).

    2. Unpack the distribution, using either gunzip/tar or unzip.

    3. In your stylesheet import or include either the main stylesheet, stdlib.xsl, or the stylesheet module you wish to use, such as string.xsl. This example assumes that the distribution has been extracted into the same directory as your own stylesheet:

      <xsl:import href="stdlib.xsl"/>
      
  • Import or include either the main stylesheet, or the stylesheet module you wish to use, directly from the library website; http://xsltsl.sourceforge.net/modules/. The modules directory always contains the latest stable release. For example:

    <xsl:import href="http://xsltsl.sourceforge.net/modules/stdlib.xsl"/>
    

    Older versions of the library are available in subdirectories. For example, to access version 1.1 of the library use:

    <xsl:import href="http://xsltsl.sourceforge.net/modules/1.1/stdlib.xsl"/>
    

Next, add XML Namespace declarations for the modules you wish to use. For example, to use templates from the string module, your stylesheet should have the following declaration:

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:str="http://xsltsl.org/string">

<xsl:import href="http://xsltsl.sourceforge.net/modules/stdlib.xsl"/>

Finally, use a template with the call-template element. Most templates require parameters, which are passed using the with-param element. For example:

<xsl:template match="foo">
  <xsl:call-template name="str:subst">
    <xsl:with-param name="text" select="."/>
    <xsl:with-param name="replace">a word</xsl:with-param>
    <xsl:with-param name="with">another word</xsl:with-param>
  </xsl:call-template>
</xsl:template>

Chapter 2. Obtaining The Library

The XSLT Standard Library is available for download as either:

Chapter 3. Getting Involved

Contributions to the project are most welcome, and may be in the form of stylesheet modules, patches, bug reports or sample code. Any contributed code must use the LGPL license to be accepted into the library.

See the SourceForge Project Page http://sourceforge.net/projects/xsltsl/ for information on the development of the project. Bug reports may be submitted here.

See the project Web Page http://xsltsl.sourceforge.net/ for documentation.

There are three mailing lists for the project:

Discussion of the use of xsltsl.

Discussion of the development of xsltsl.

Project announcements.

Chapter 4. XML Namespaces

Apart from the XSLT XML Namespace (http://www.w3.org/1999/XSL/Transform), xsltsl employs a number of XML Namespaces to allow inclusion of the library in developer stylesheets. In addition, documentation is defined in a separate namespace.

Each module is allocated a namespace URI by appending the module name to the URI for the project, http://xsltsl.org/. For example, the string module has the namespace URI http://xsltsl.org/string.

All documentation is written using an extension of DocBook designed for embedding DocBook into XSLT stylesheets. The namespace URI for DocBook embedded in stylesheets is http://xsltsl.org/xsl/documentation/1.0

Chapter 5. Engineering Standards

In order to maintain a high engineering standard, all modules and contributions to the xsltsl project must adhere to the following coding and documentation standards. Submissions which do not meet (or exceed) this standard will not be accepted.

  • All stylesheets must be indented, with each level indented by two spaces. NB. a simple stylesheet could be used to enforce/fix this.

  • Templates are named using a qualified name (QName). The namespace URI for the template's containing stylesheet is assigned as above.

  • Parameters for templates should use sensible names. Where possible (or if in doubt), follow these conventions:

    • A parameter containing a single node is named node. Where more than one parameter contains a single node, the suffix Node is appended to the parameter name, eg. referenceNode

    • A parameter which potentially contains multiple nodes is named nodes. Where more than one parameter potentially contains multiple nodes, the suffix Nodes is appended to the parameter name, eg. copyNodes

    • A parameter which contains a string value is named text.

  • All templates in each stylesheet must be documented. A template is documented as a DocBook RefEntry.

  • Every stylesheet must include a test suite. The test system is in the test subdirectory. See test/test.html for further details.

An example stylesheet has been provided, which acts as a template for new stylesheet modules.

Chapter 6. Related Work

The EXSLT project is creating a library to standardise extension functions. The XSLT Standard Library is complementary to the EXSLT project.

Chapter 7. Reference Documentation

Reference documentation is available for each module.

String Processing

Nodes

Date/Time Processing

Mathematics

URI (Uniform Resource Identifier) Processing

Comparing Nodesets

Generating XML Markup

Presentation Media Support

Example