XSLT transforms library
Copyright J.M. Vanel 2000-2004 - under Lesser GNU Public Licence
Last update:


This is a nice collection of useful XSLT transforms, models and reusable fragments under GPL, involving HTML tables, XML Schema, HTML GUI, MathML, SQL analogy, etc. This has been developped as part of the "Worlwide Botanical Knowledge Base" project, ( http://wwbota.free.fr/ ).

The transforms fall within the following (mutually exclusive) categories :

proof of concept
aims at showing the possibilities of XSLT in various domains; far from production quality
small examples
design pattern
starting points of frequent use to write transforms, not for direct use but after editing (about design patterns see the book "Design Patterns" by E. Gamma et al.)
XSLT transforms of production quality, for direct use
template library
for use as imported stylesheet, of production quality

Other similar ressources

I strongly recommend Michael Kay's book (the author of the Saxon processor), whose sources can be downloaded from wrox.com .


We develop a series of useful transforms, either acting on the structure of the document, or performing generic transforms (e.g. creating an index of words), or acting on well-knows documents (e.g. XML Schema, SVG, XHTML, ...), or merging or splitting in various ways. These transforms should be able to be re-assembled (by chaining-piping, import, or other combinations) to perform complex tasks out of simple bricks. This is coherent with the vision of an XML-centered application (see Extensible browsers and XML-compliant applications on this site). This way we could also do something as useful and flexible as the Unix shells commands (wc, sed, grep, ...), and C++ Standard Template library. This sub-project is under Lesser GNU Public Licence (LGPL), so contributions are wellcome!

An application of XSLT transforms library is XMLPublication, a Web document publication framework through XML. As an example, XMLPublication was used with this HTML page as the source for generation (see XMLPub generated pages). Currently there are some XSLT transforms here that are outdated with respect to the XMLPublication distribution, and also many useful transforms there that are not here, but this will be fixed .

Transforms marqued with XSLT 1.1 or 2.0 necessitate Saxon . Mirror on WWKBK SourceForge project Page .

XSLT 2.0 and XQuery

Many transforms included here are obsoleted by the new W3C "standard", XSLT 2.0, still work in progress (not yet a Recommandation). XSLT 2.0 is based on the new XPath 2.0. There is a new library of XPath functions. And finally, there is a new transformation language, XQuery, that is positioned as a query language like SQL and OQL, but has the same power as XSLT.
The resemblances between XQuery and XSLT  are:
The difference between XQuery and XSLT  are:
The project has selected 2 Xquery processors:

The XSLT transforms library

XML source XSLT Description Category Domain Output
FinancialReport_1.htm HTMLtable2XML.xslt from HTML table to XML; generates XML tags from first row <th> tags UPDATEDXSLT 1.1; see present XHTML page transformed production XHTML FinancialReport_1.xml
test.xml queryOnSubElement.xslt selects a given tag according to the content of a subelement pedagogical query queryOnSubElement.xml
pense-bete.xml selectTagName.xslt selects only given tag at any embedding level, and its content recursively pedagogical query selectTagName.xml
test.xml identquery.xslt identity transform pedagogical



identity transform 2 : a good starting point to write XSLT transforms design pattern

test.xml identquery-mode.xslt identity transform 2 with mode attribute :an even better starting point to write XSLT transforms design pattern

jetty.xml change-jetty.xml.xslt Changes the port number and disables the AJP13 server in Jetty Web server. Illustrates how to find a needle in a hay stack, change that needle, and leave the rest unchanged. Reuses identity transform 2 production, but applies to very specific documents server configuration jetty-new.xml
emptyElements.xml suppressEmptyElements.xslt suppress empty elements (i.e. elements with no text content) production structure emptySuppressed.xml
testHREF.xml selectHREF.xslt extract href attributes; example of text mode output pedagogical XHTML selectHREF.txt
testHREF.xml attributes2elements.xslt replace attributes with elements; reuses identity transform 2 production structure attributes2elements.xml
document-to-split.xml split.xslt split named first-level elements into files (XSLT 1.1) NEW pedagogical file structure one file per first-level element

append.xslt merge after last first-level element of document at URL $main all first-level elements of input document . production file structure

wrapper.xslt wrap a nodeset fragment of XML inside an XML document. An attribute marker is used to tell where to insert the fragment. library file structure

auto-sufficient stylesheet

difference-by-value.xslt difference by string value of first-level elements of trees in $v1 and $v2. Outputs a list of nodes in $v1 not having same string value as one of $v2 . library string, set
test-make-words-list.xslt: auto-sufficient stylesheet make-words-list.xslt from a whitespace-separated string, outputs an sorted or unsorted list of unique words occuring in $string . library string
test-split-string.xslt: auto-sufficient stylesheet split-string.xslt from a whitespace-separated string, outputs an list of words occuring in $string . library string

unique.xslt Suppresses consecutive elements having same value. Parameter: $nodes : a node set (typically sorted) Output: node set with consecutive elements having same value suppressed library

sampleXMLSchema.xml XMLSchemac++.xslt generates C++ declarations from a XML Schema proof of concept XML_Schema XMLSchema.cpp
sampleXMLSchema.xml XMLSchema2Example.xslt XML Schema ==> typical instance of XML document proof of concept XML_Schema instanceFromSchema.xml
sampleXMLSchema.xml XMLSchema2DTD.xslt XML Schema ==> DTD proof of concept XML_Schema DTDFromSchema.dtd
sampleXMLSchema.xml XMLSchema2GUI.xslt XML Schema ==> HTML input form ( NEW : updated to XML Schema Recommandation) proof of concept XML_Schema GUIFromSchema.xml


XML Schema ==> HTML Easy XML search: XPath helper production XML_Schema XPath-helper.html


NEW: XML Schema ==> HTML documentation work in progress XML_Schema XMLSchemaHTMLdoc.html
FinancialReport_1.xml example2Schema.xslt From any XML, make a valid W3C XML Schema; also offers statistics about number of elements. XSLT 2.0 proof of concept XML_Schema


relationalDB.xml example2simpleSchema.xslt From any XML, make a (non W3C) simple XML Schema; also offers statistics about number of elements production
relationalDB.xml SQL-join.xslt How to do in XSLT the equivalent of a SQL join pedagogical reference join.xml
sphere.MathML.xml Mathml2c.xslt generate C++ code from MathML declarations representing 3D geometry proof of concept MathML sphere.cpp
substituteEltName.xml substituteEltName.xslt substitute occurences of element <e1> in namespace N1 into element <e2> in namespace N2 pedagogical structure substitutedElt.xml

from XMI 1.1 (UML), make a summary as an HTML table with 5 colums
production XMI

How to transform

Alas only Saxon implements the useful XSLT 1.1 extension allowing to mix freely tree fragments and node lists. This is why Xalan emits the message:
XSLT Error (org.apache.xpath.XPathException): Can not convert #RTREEFRAG to a NodeList!

Projects of new transforms