HOME
The Info List - XSLT


--- Advertisement ---



XSLT
XSLT
( Extensible Stylesheet Language Transformations) is a language for transforming XML
XML
documents into other XML
XML
documents,[1] or other formats such as HTML
HTML
for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript
PostScript
and PNG.[2] XSLT
XSLT
1.0 is widely supported in modern web browsers [3]. The original document is not changed; rather, a new document is created based on the content of an existing one.[4] Typically, input documents are XML
XML
files, but anything from which the processor can build an XQuery and XPath Data Model
XQuery and XPath Data Model
can be used, such as relational database tables or geographical information systems.[1] Although XSLT
XSLT
is designed as a special-purpose language for XML transformation, the language is Turing-complete, making it theoretically capable of arbitrary computations.

Contents

1 History 2 Design and processing model 3 Processor implementations

3.1 Performance

4 XPath 5 XQuery compared 6 Media types 7 Examples

7.1 Example 1 (transforming XML
XML
to XML) 7.2 Example 2 (transforming XML
XML
to XHTML)

8 See also 9 References 10 Further reading 11 External links

History[edit] XSLT
XSLT
is influenced by functional languages,[5] and by text-based pattern matching languages like SNOBOL and AWK. Its most direct predecessor is DSSSL, which did for SGML
SGML
what XSLT
XSLT
does for XML.[6]

XSLT
XSLT
1.0: XSLT
XSLT
was part of the World Wide Web Consortium
World Wide Web Consortium
(W3C)'s Extensible Stylesheet Language (XSL) development effort of 1998–1999, a project that also produced XSL-FO and XPath. Some members of the standards committee that developed XSLT, including James Clark, the editor, had previously worked on DSSSL. XSLT
XSLT
1.0 was published as a W3C
W3C
recommendation in November 1999.[7] XSLT
XSLT
2.0: after an abortive attempt to create a version 1.1 in 2001,[8] the XSL working group joined forces with the XQuery working group to create XPath
XPath
2.0,[9] with a richer data model and type system based on XML
XML
Schema. Building on this is XSLT
XSLT
2.0,[10] developed under the editorship of Michael Kay, which reached recommendation status in January 2007.[11] As of 2010, however, XSLT
XSLT
1.0[12] is still widely used, since 2.0 is not supported natively in web browsers or for environments like LAMP. XSLT
XSLT
3.0: became a W3C
W3C
Recommendation on 8 June 2017. The main new features are:[13]

Streaming transformations: in previous versions the entire input document had to be read into memory before it could be processed,[14] and output could not be written until processing had finished (although Saxon does have a streaming extension). The working draft allows XML
XML
streaming which will be useful for processing documents too large to fit in memory, or when transformations are chained in XML Pipelines. Improvements to the modularity of large stylesheets. Improved handling of dynamic errors with, for example, an xsl:try instruction. Functions can now be arguments to other (higher-order) functions.

Design and processing model[edit]

Diagram of the basic elements and process flow of Extensible Stylesheet Language Transformations.

The XSLT
XSLT
processor takes one or more XML
XML
source documents, plus one or more XSLT
XSLT
stylesheets, and processes them to produce an output document. In contrast to widely implemented imperative programming languages like C, XSLT
XSLT
is declarative.[15] The basic processing paradigm is pattern matching.[16] Rather than listing an imperative sequence of actions to perform in a stateful environment, template rules only define how to handle a node matching a particular XPath-like pattern, if the processor should happen to encounter one, and the contents of the templates effectively comprise functional expressions that directly represent their evaluated form: the result tree, which is the basis of the processor's output. The processor follows a fixed algorithm.[17] First, assuming a stylesheet has already been read and prepared, the processor builds a source tree from the input XML
XML
document. It then processes the source tree's root node, finds the best-matching template for that node in the stylesheet, and evaluates the template's contents. Instructions in each template generally direct the processor to either create nodes in the result tree, or to process more nodes in the source tree in the same way as the root node. Output derives from the result tree. Processor implementations[edit]

Altova Raptor XML
XML
Server: cross-platform engine that supports XSLT
XSLT
1.0 and 2.0, most of XPath
XPath
3.0, and some features from the XSLT
XSLT
3.0 working draft; also XQuery. Allows command line operations and interfaces to COM, Java, and .NET[18] and also includes a built-in HTTP server. Exselt:[19] A streaming XSLT
XSLT
3.0 processor which runs on the .NET framework written in F#. Fully supports the XSLT
XSLT
3.0 Draft, XPath
XPath
3.0 Recommendation and XDM 3.0 Recommendation standards. libxslt is a free library released under the MIT License that can be reused in commercial applications. It is based on libxml and implemented in C for speed and portability. It supports XSLT
XSLT
1.0 and EXSLT extensions.[20]

It can be used at the command line via xsltproc[21] which is included in macOS[22] and many Linux distributions, and can be used on Windows via Cygwin.[23] The WebKit
WebKit
and Blink layout engines, used for example in the Safari and Chrome web browsers respectively, uses the libxslt library to do XSL transformations.[24] Bindings exist for Python,[25] Perl,[26] Ruby,[27] PHP,[28] Common Lisp,[29] Tcl,[30] and C++.[31]

MS XML
XML
and .NET. MS XML
XML
includes an XSLT
XSLT
1.0 processor. From MS XML
XML
4.0 it includes the command line utility msxsl.exe.[32] Saxon: an XSLT
XSLT
3.0 and XQuery 3.1 processor with open-source and proprietary versions for stand-alone operation and for Java, JavaScript[33] and .NET. QuiXSLT: an XSLT
XSLT
3.0 processor doing streaming implemented in Java by Innovimax and INRIA.[34] Xalan: an open source XSLT
XSLT
1.0 processor from the Apache Software Foundation available stand-alone and for Java and C++. Web browsers: Safari, Chrome, Firefox, Opera and Internet Explorer all support XSLT
XSLT
1.0. None support XSLT
XSLT
2.0 natively, although the third party products like Saxon-CE[35] and Frameless[36] can provide this functionality.[37][38] Browsers can perform on-the-fly transformations of XML
XML
files and display the transformation output in the browser window. This is done either by embedding the XSL in the XML
XML
document or by referencing a file containing XSL instructions from the XML document. The latter may not work with Chrome because of its security model.[39] XMLStarlet is "a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML
XML
documents". It can "apply XSLT
XSLT
stylesheets to XML
XML
documents" and does not require Java. It uses libxslt and supports XSLT
XSLT
1.0. Xuriella[40] and Plexippus-xpath[41] are XSLT
XSLT
1.0 processors written in Common Lisp.

Performance[edit] Most early XSLT
XSLT
processors were interpreters. More recently, code generation is increasingly common, using portable intermediate languages (such as Java bytecode or .NET Common Intermediate Language) as the target. However, even the interpretive products generally offer separate analysis and execution phases, allowing an optimized expression tree to be created in memory and reused to perform multiple transformations. This gives substantial performance benefits in online publishing applications, where the same transformation is applied many times per second to different source documents.[42] This separation is reflected in the design of XSLT
XSLT
processing APIs (such as JAXP). Early XSLT
XSLT
processors had very few optimizations. Stylesheet documents were read into Document Object Models and the processor would act on them directly. XPath
XPath
engines were also not optimized. Increasingly, however, XSLT
XSLT
processors use optimization techniques found in functional programming languages and database query languages, such as static rewriting of an expression tree (e.g., to move calculations out of loops), and lazy pipelined evaluation to reduce the memory footprint of intermediate results (and allow "early exit" when the processor can evaluate an expression such as following-sibling::*[1] without a complete evaluation of all subexpressions). Many processors also use tree representations that are significantly more efficient (in both space and time)[43] than general-purpose DOM implementations. In June 2014, Debbie Lockett and Michael Kay introduced an open-source benchmarking framework for XSLT
XSLT
processors called XT-Speedo.[44] XPath[edit] Further information: XPath XSLT
XSLT
uses XPath
XPath
to identify subsets of the source document tree and perform calculations. XPath
XPath
also provides a range of functions, which XSLT
XSLT
itself further augments. XSLT
XSLT
1.0 uses XPath
XPath
1.0, while XSLT
XSLT
2.0 uses XPath
XPath
2.0. XSLT
XSLT
3.0 will work with either XPath
XPath
3.0 or 3.1. In the case of 1.0 and 2.0, the XSLT
XSLT
and XPath
XPath
specifications were published on the same date. With 3.0, however, they were no longer synchronized; XPath
XPath
3.0 became a Recommendation in April 2014, followed by XPath
XPath
3.1 in February 2017; XSLT
XSLT
3.0 followed in June 2017. XQuery compared[edit] Further information: XQuery §  XQuery and XSLT
XSLT
compared XSLT
XSLT
functionalities overlap with those of XQuery, which was initially conceived as a query language for large collections of XML
XML
documents. The XSLT
XSLT
2.0 and XQuery 1.0 standards were developed by separate working groups within W3C, working together to ensure a common approach where appropriate. They share the same data model, type system, and function library, and both include XPath
XPath
2.0 as a sublanguage. The two languages, however, are rooted in different traditions and serve the needs of different communities. XSLT
XSLT
was primarily conceived as a stylesheet language whose primary goal was to render XML
XML
for the human reader on screen, on the web (as web template language), or on paper. XQuery was primarily conceived as a database query language in the tradition of SQL. Because the two languages originate in different communities, XSLT
XSLT
is stronger in its handling of narrative documents with more flexible structure, while XQuery is stronger in its data handling, for example when performing relational joins.[citation needed] Media types[edit] The <output> element can optionally take the attribute media-type, which allows one to set the media type (or MIME type) for the resulting output, for example: <xsl:output output="xml" media-type="application/xml"/>. The XSLT
XSLT
1.0 recommendation recommends the more general attribute types text/xml and application/xml since for a long time there was no registered media type for XSLT. During this time text/xsl became the de facto standard. In XSLT
XSLT
1.0 it was not specified how the media-type values should be used. With the release of the XSLT
XSLT
2.0, the W3C
W3C
recommended the registration of the MIME media type application/xslt+xml[45] and it was later registered with the Internet Assigned Numbers Authority.[46] Pre-1.0 working drafts of XSLT
XSLT
used text/xsl in their embedding examples, and this type was implemented and continues to be promoted by Microsoft in Internet Explorer[47] and MSXML. It is also widely recognized in the xml-stylesheet processing instruction by other browsers. In practice, therefore, users wanting to control transformation in the browser using this processing instruction are obliged to use this unregistered media type.[48] Examples[edit] These examples use the following incoming XML
XML
document

<?xml version="1.0" ?> <persons> <person username="JS1"> <name>John</name> <family-name>Smith</family-name> </person> <person username="MI1"> <name>Morka</name> <family-name>Ismincius</family-name> </person> </persons>

Example 1 (transforming XML
XML
to XML)[edit] This XSLT
XSLT
stylesheet provides templates to transform the XML
XML
document:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/>

<xsl:template match="/persons"> <root> <xsl:apply-templates select="person"/> </root> </xsl:template>

<xsl:template match="person"> <name username=" @username "> <xsl:value-of select="name" /> </name> </xsl:template>

</xsl:stylesheet>

Its evaluation results in a new XML
XML
document, having another structure:

<?xml version="1.0" encoding="UTF-8"?> <root> <name username="JS1">John</name> <name username="MI1">Morka</name> </root>

Example 2 (transforming XML
XML
to XHTML)[edit] Processing the following example XSLT
XSLT
file

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

<xsl:template match="/persons"> <html> <head> <title>Testing XML
XML
Example</title> </head> <body> <h1>Persons</h1> <ul> <xsl:apply-templates select="person"> <xsl:sort select="family-name" /> </xsl:apply-templates> </ul> </body> </html> </xsl:template>

<xsl:template match="person"> <li> <xsl:value-of select="family-name"/><xsl:text>, </xsl:text><xsl:value-of select="name"/> </li> </xsl:template>

</xsl:stylesheet>

with the XML
XML
input file shown above results in the following XHTML (whitespace has been adjusted here for clarity):

<?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Testing XML
XML
Example</title> </head> <body> <h1>Persons</h1> <ul> <li>Ismincius, Morka</li> <li>Smith, John</li> </ul> </body> </html>

This X HTML
HTML
generates the output below when rendered in a web browser.

Rendered X HTML
HTML
generated from an XML
XML
input file and an XSLT transformation.

In order for a web browser to be able automatically to apply an XSL transformation to an XML
XML
document on display, an XML
XML
stylesheet processing instruction can be inserted into XML. So, for example, if the stylesheet in Example 2 above were available as "example2.xsl", the following instruction could be added to the original incoming XML:[49]

<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>

In this example, text/xsl is technically incorrect according to the W3C
W3C
specifications[49] (which say the type should be text/xml), but it is the only media type that is widely supported across browsers as of 2009. See also[edit]

XSLT elements – a list of some commonly used XSLT
XSLT
structures. Muenchian grouping – a dialect differential between XSLT1 and XSLT2+. Extensible Stylesheet Language – a family of languages of which XSLT is a member XQuery and XSLT
XSLT
compared XSL formatting objects or XSL-FO – An XML-based language for documents, usually generated by transforming source documents with XSLT, consisting of objects used to create formatted output Identity transform – a starting point for filter chains that add or remove data elements from XML
XML
trees in a transformation pipeline Apache Cocoon
Apache Cocoon
– a Java-based framework for processing data with XSLT and other transformers. Omnimark – another structured text processing language (proprietary software) Xs3p – is an XSLT
XSLT
stylesheet that generates X HTML
HTML
documentation from XML
XML
Schema Definition language (XSD) schema.

References[edit]

^ a b "Transformation". 2012-09-19.  ^ " XML
XML
Output Method". 2012-09-19.  ^ "What is XSLT
XSLT
Used For?". 2018-02-07.  ^ "Introduction". XSL Transformations (XSLT) Version 1.0 W3C Recommendation. W3C. 16 November 1999. Retrieved November 7, 2012.  ^ Michael Kay. "What kind of language is XSLT?". Retrieved July 8, 2016.  ^ "A Proposal for XSL". W3C. Retrieved November 7, 2012.  ^ " XML
XML
and Semantic Web W3C
W3C
Standards Timeline" (PDF).  ^ " XSL Transformations (XSLT) Version 1.1". W3.org. 2001-08-24. Retrieved 2014-07-12.  ^ " XML
XML
Path Language (XPath) 2.0 (Second Edition)". W3.org. 2010-12-14. Retrieved 2014-07-12.  ^ " XSL Transformations (XSLT) Version 2.0". W3.org. 2007-01-23. Retrieved 2014-07-12.  ^ " XML
XML
and Semantic Web W3C
W3C
Standards Timeline" (PDF). 2012-02-04.  ^ " XSL Transformations (XSLT)". W3.org. 1999-11-16. Retrieved 2014-07-12.  ^ "What's New in XSLT
XSLT
3.0?". w3. Retrieved 6 January 2014.  ^ Kay, Michael. "A Streaming XSLT
XSLT
Processor". Balisage: The Markup Conference 2010 Proceedings. Retrieved 15 February 2012.  ^ "Discover the Wonders of XSLT: XSLT
XSLT
Quirks". XSLT
XSLT
is a very specialized language with a distinct declarative flavor.  ^ Kay, Michael. "What kind of language is XSLT?". IBM. Retrieved 13 November 2013.  ^ " XSLT
XSLT
Definitions". XSLT
XSLT
declarations define a set of rules and guidelines that are applied during processing according to a predefined algorithm.  ^ "RaptorXML". Retrieved 21 August 2013.  ^ "Exselt XSLT
XSLT
Processor". Exselt. 2015-06-06.  ^ "The XSLT
XSLT
C library for GNOME: libxslt". Retrieved 23 November 2012.  ^ "The XSLT
XSLT
C library for GNOME: The xsltproc tool". Retrieved 23 November 2012.  ^ "xsltproc man page". Retrieved 23 November 2012.  ^ "New package: libxslt". Retrieved 23 November 2012.  ^ "The WebKit
WebKit
Open Source Project - XSLT". Retrieved 2009-10-25.  ^ "The XML
XML
C parser and toolkit of Gnome: Python and bindings". Retrieved 23 November 2012.  ^ "XML::Lib XSLT
XSLT
- Interface to the GNOME libxslt library". CPAN. Retrieved 23 November 2012.  ^ "libxslt-ruby". Retrieved 23 November 2012.  ^ "libxml". Retrieved 23 November 2012.  ^ "cl-libxml2 High-level wrapper around libxml2 and libxslt libraries".  ^ "TclXML". Retrieved 21 May 2013.  ^ "libxml++". sourceforge.net. Retrieved 23 November 2012.  ^ "Command Line Transformation Utility (msxsl.exe)". Microsoft. Retrieved 22 October 2012.  ^ "Saxon Client Edition 1.0". Saxonica. Retrieved 14 August 2012.  ^ "QuiXSLT » QuiX-Tool Suite". Project.inria.fr. 2013-11-14. Retrieved 2014-07-12.  ^ Saxonica. "About Saxon-CE". Retrieved 2012-06-16.  ^ Frameless. "Frameless XSLT/ XPath
XPath
2.0 processor". Retrieved 2014-06-09.  ^ Delpratt, O'Neil (June 2013). " XML
XML
on the web: is it still relevant?". XML
XML
London 2013: 35–48. doi:10.14337/XMLLondon13.Delpratt01. ISBN 978-0-9926471-0-0.  ^ Broersma, Robbert; van der Kolk, Yolijn (June 2014). "Frameless for XML
XML
- The Reactive Revolution". XML
XML
London 2014: 128–132. doi:10.14337/XMLLondon14.Broersma01. ISBN 978-0-9926471-1-7.  ^ "Can't read an XML
XML
and/or XSLT
XSLT
in Google Chrome". Stack Overflow. 2014. Retrieved 12 July 2014.  ^ "Xuriella XSLT".  ^ "Plexippus XPath".  ^ Saxon: Anatomy of an XSLT
XSLT
processor - Article describing implementation & optimization details of a popular XSLT
XSLT
processor. ^ Lumley, John; Kay, Michael (June 2015). "Improving Pattern Matching Performance in XSLT". XML
XML
London 2015: 9–25. doi:10.14337/XMLLondon15.Lumley01. ISBN 978-0-9926471-2-4.  ^ Kay, Michael; Lockett, Debbie (June 2014). "Benchmarking XSLT Performance". XML
XML
London 2014: 10–23. doi:10.14337/XMLLondon14.Kay01. ISBN 978-0-9926471-1-7.  ^ " XSL Transformations (XSLT) Version 2.0". W3C. Retrieved 19 October 2012.  ^ "Application Media Types". IANA. Retrieved 19 October 2012.  ^ " XSLT
XSLT
Requirements for Viewing XML
XML
in a Browser". Microsoft. Retrieved 19 October 2012.  ^ Kay, Michael (2008). XSLT
XSLT
2.0 and XPath
XPath
2.0 Programmer's Reference. Wiley. p. 100. ISBN 978-0-470-19274-0.  ^ a b " XSL Transformations (XSLT) Version 1.0: W3C Recommendation – Embedding Stylesheets". W3C. 16 November 1999. Retrieved 20 September 2016. 

Further reading[edit]

XSLT
XSLT
by Doug Tidwell, published by O’Reilly (ISBN 0-596-00053-7) XSLT
XSLT
Cookbook by Sal Mangano, published by O’Reilly (ISBN 0-596-00974-7) XSLT
XSLT
2.0 Programmer's Reference by Michael Kay (ISBN 0-764-56909-0) XSLT
XSLT
2.0 and XPath
XPath
2.0 Programmer's Reference by Michael Kay (ISBN 978-0-470-19274-0) XSLT
XSLT
2.0 Web Development by Dmitry Kirsanov (ISBN 0-13-140635-3) XSL Companion, 2nd Edition by Neil Bradley, published by Addison-Wesley (ISBN 0-201-77083-0) XSLT
XSLT
and XPath
XPath
on the Edge (Unlimited Edition) by Jeni Tennison, published by Hungry Minds Inc, U.S. (ISBN 0-7645-4776-3) XSLT
XSLT
& XPath, A Guide to XML
XML
Transformations by John Robert Gardner and Zarella Rendon, published by Prentice-Hall (ISBN 0-13-040446-2) XSL-FO by Dave Pawson, published by O'Reilly (ISBN 978-0-596-00355-5)

External links[edit]

Wikibooks has a book on the topic of: XML
XML
- Managing Data Exchange/ XSLT
XSLT
and Style Sheets

Wikimedia Commons has media related to Extensible Stylesheet Language Transformations.

Documentation

XSLT
XSLT
1.0 W3C
W3C
Recommendation XSLT
XSLT
2.0 W3C
W3C
Recommendation XSLT
XSLT
3.0 W3C
W3C
Recommendation XSLT
XSLT
- MDC Docs by Mozilla Developer Network XSLT
XSLT
Reference (MSDN) XSLT
XSLT
Elements (Saxon) XSLT
XSLT
introduction and reference

XSLT
XSLT
code libraries

EXSLT is a widespread community initiative to provide extensions to XSLT. F XSL is a library implementing support for Higher-order functions in XSLT. F XSL is written in XSLT
XSLT
itself. The XSLT
XSLT
Standard Library xsltsl, provides the XSLT
XSLT
developer with a set of XSLT
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. Kernow A GUI for Saxon that provides a point and click interface for running transforms. xslt.js – Transform XML
XML
with XSLT
XSLT
JavaScript
JavaScript
library that transforms XML
XML
with XSLT
XSLT
in the browser.

v t e

XSL

XSLT

elements

XSL-FO XPath

1.0 2.0

v t e

World Wide Web Consortium
World Wide Web Consortium
(W3C)

Products and standards

Recommendations

ActivityPub ARIA Canonical XML CDF CSS DOM Geolocation API HTML
HTML
(HTML5) ITS JSON-LD Linked Data Notifications MathML Micropub OWL P3P PLS RDF RDF Schema SISR SKOS SMIL SOAP SRGS SRI SSML SVG SCXML SPARQL Timed text VoiceXML Web storage WSDL Webmention WebSub XForms XHTML XHTML+RDFa XInclude XLink XML XML
XML
Base XML
XML
Encryption XML
XML
Events XML
XML
Information Set XML
XML
namespace XML
XML
Schema XML
XML
Signature XOP XPath XPath
XPath
2.0 XPointer XProc XQuery XSL XSL-FO XSLT (elements)

Notes

IndieAuth JF2 Post Type Discovery XAdES XHTML+SMIL XUP

Working drafts

CCXML CURIE EME InkML MSE RIF SMIL Timesheets sXBL WICD XFDL XFrames XBL XMLHttpRequest

Guidelines

Web Content Accessibility Guidelines

Initiative

Multimodal Interaction Activity (MMI) Markup Validation Service Web Accessibility Initiative WebPlatform

Deprecated

C-HTML HDML JSSS PGML VML XHTML+MathML+SVG

Organizations

Advisory Committee (AC) World Wide Web Foundation

Elected groups

Advisory Board (AB) Technical Architecture Group (TAG)

Working groups

CSS Geolocation Social Web SVG Web Hypertext Application Technology (WHATWG) Web Platform

Closed groups

Device Description (DDWG) HTML WebOnt (Semantic Web Activity)

Software

CERN httpd Libwww

Browsers

Line Mode (1990–) Arena (1993–98) Agora (1994–97) Argo (1994–97) Amaya (browser/editor, 1996–2012)

Conferences

International World Wide Web Conference
International World Wide Web Conference
(IW3C)

Steering Committee (IW3C2) First conference ("WWW1", 1994)

Authority control

.