- XSL Transformations
infobox file format
name = XSL Transformations
extension = .xsl, .xslt
mime = application/xslt+xml [ [http://www.w3.org/TR/xslt20/#xslt-mime-definition XSL Transformations (XSLT) Version 2.0 ] ]
owner = [http://www.w3.org/ World Wide Web Consortium]
creatorcode =
genre =Stylesheet language
containerfor =
containedby =
extendedfrom =XML
extendedto =
standard = [http://www.w3.org/TR/xslt 1.0 (Recommendation)] ,
[http://www.w3.org/TR/xslt20/ 2.0 (Recommendation)]Extensible Stylesheet Language Transformations (XSLT) is an
XML -based language used for the transformation of XML documents into other XML or "human-readable" documents. The original document is not changed; rather, a new document is created based on the content of an existing one. [http://www.w3.org/TR/xslt#section-Introduction XSL Transformations (XSLT) ] ] The new document may be serialized (output) by the processor in standard XML syntax or in another format, such asHTML orplain text .See e.g., http://www.w3.org/TR/xslt#output, specifying alternate output methods.] XSLT is most often used to convert data between differentXML schema s or to convert XML data intoHTML orXHTML documents forweb page s, creating adynamic web page , or into an intermediate XML format that can be converted to PDF documents.As a language, XSLT is influenced by functional languages, [cite web | url=http://www.idealliance.org/papers/extreme/proceedings/html/2006/Novatchev01/EML2006Novatchev01.html | author=Dimitre Novatchev | title=Higher-Order Functional Programming with XSLT 2.0 and FXSL | accessmonthday=January 18 | accessyear=2007|work=ExtremeMarkupLanguages] and by text-based pattern matching languages like
SNOBOL and awk. Its most direct predecessor wasDSSSL , a language that performed the same function forSGML that XSLT performs for XML [http://www.w3.org/TR/NOTE-XSL.html] . XSLT can also be considered as atemplate processor .XSLT is
Turing complete . [Kepser, Stephan. (2004).] [ [http://www.mulberrytech.com/Extreme/Proceedings/html/2004/Kepser01/EML2004Kepser01.html A Simple Proof for the Turing-Completeness of XSLT and XQuery] ". International Digital Enterprise Alliance.] [ [http://www.unidex.com/turing/utm.htm Universal Turing Machine in XSLT ] ] [ [http://www.refal.net/~korlukov/tm/ index ] ]Origins
XSLT is developed by the
World Wide Web Consortium (W3C). The most recent version is XSLT 2.0 [http://www.w3.org/TR/xslt20/] , which reachedW3C recommendation status on 23 January 2007. As of 2008, however, XSLT 1.0 [http://www.w3.org/TR/xslt/] is still more widely used and implemented.Originally, XSLT was part of the W3C's
Extensible Stylesheet Language (XSL) development effort of 1998–1999, a project that also produced XSL Formatting Objects and the XML Path Language,XPath . The editor of the first version was James Clark. XSLT 1.0 was published as a Recommendation by the W3C on 16 November 1999. After an abortive attempt to create a version 1.1 in 2001 [http://www.w3.org/TR/xslt11/] , the XSL working group joined forces with theXQuery working group to createXPath 2.0 [http://www.w3.org/TR/xpath20/] , with a richer data model and type system based on XML Schema. XSLT 2.0, developed under the editorship of Michael Kay, was built on this foundation in 2002–2006.Most of this article is applicable to both XSLT versions; any differences are noted in the text.
Overview
The XSLT processing model involves:
* one or more XML "source" documents;
* one or more XSLT "stylesheet" modules;
* the XSLT template processing engine (the "processor"); and
* one or more "result" documents.The XSLT processor ordinarily takes two input documentsTypically, documents are XML files, but the specifications avoid excluding other representations, such as in-memory
DOM trees or other conforming input streams.] —an XML source document, and an XSLT stylesheet—and produces an output document. The XSLT stylesheet contains the XSLT program text (or ‘source code’ in other languages) and is itself an XML document. It describes a collection of "template rules": "instructions" and other directives that guide the processor in the production of the output document.Template rule processing
The XSLT language is declarative—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: Assuming a stylesheet has already been read and prepared, the processor builds a "source tree" from the input XML document. It then starts by processing the source tree's root node, finding in the stylesheet the best-matching template for that node, and evaluating the template's contents. Instructions in each template generally direct the processor to either create nodes in the result tree, or process more nodes in the source tree in the same way as the root node. Output is derived from the result tree.
Processor implementations
XSLT processor implementations fall into two main categories: server-side, and client-side.
Although client-side XSLT processing has been available in
Microsoft 'sInternet Explorer since 1999 (or even earlier, but in a form that was incompatible with the W3C specifications), adoption has been slower because of the widespread deployment of older and alternative browsers without XSLT support. For similar reasons, adoption of XSLT 2.0 in such environments is likely to be some years away.XSLT processors may be delivered as standalone products, or as components of other software including web browsers, application servers, frameworks such as Java and .NET, or even operating systems. For example,
Windows XP comes with theMSXML 3 library, which includes an XSLT processor. Earlier versions may be upgraded and there are many alternatives. See the external links section.Performance
The performance of XSLT processors has steadily improved as the technology has become more mature, although the very first processor, James Clark's xt, was unbeaten for several years [ [http://www.xml.com/pub/a/2001/03/28/xsltmark/index.html XML.com: XSLT Processor Benchmarks ] ] .
Most of the earlier XSLT processors were interpreters; in more recent products, 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. [ [http://www-128.ibm.com/developerworks/xml/library/x-xslt2/ Saxon: Anatomy of an XSLT processor] - An article describing the implementation and optimization details of a popular Java-based XSLT processor.] This separation is reflected in the design of XSLT processing APIs such as JAXP (
Java API for XML Processing ).Early XSLT processors had very few optimizations; stylesheet documents were read into
Document Object Model s and the processor would act on them directly.XPath engines were also not optimized. Increasingly, however, XSLT processors use the kind of optimization techniques found in functional programming languages and database query languages, notably static rewriting of the expression tree for example to move calculations out of loops, and lazy pipelined evaluation to reduce the use of memory for intermediate results and allow "early exit" when the processor can evaluate an expression such asfollowing-sibling::* [1]
without a complete evaluation of all subexpressions. Many processors also use tree representations that are much more efficient (in both space and time) than general purpose DOM implementations.XSLT and XPath
XSLT relies upon the W3C's
XPath language for identifying subsets of the source document tree, as well as for performing calculations. XPath also provides a range of functions, which XSLT itself further augments. This reliance upon XPath adds a great deal of power and flexibility to XSLT.XSLT 2.0 relies on XPath 2.0; both specifications were published on the same date. Similarly, XSLT 1.0 works with XPath 1.0.
XSLT and XQuery compared
XSLT capabilities overlap with
XQuery , which was initially conceived as a query language for large collections of XML documents.The 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 includeXPath 2.0 as a sublanguage.The two languages, however, are rooted in different traditions and serve the needs of different communities. XSLT was primarily conceived as a stylesheet language whose primary goal was to render XML for the human reader on screen, on
the web (as web template language), or on paper. XQuery was primarily conceived as adatabase query language in the tradition ofSQL .Because the two languages originate in different communities, XSLT is stronger in its handlingof narrative documents with more flexible structure, while XQuery is stronger in its data handling,for example when performing relational joins.
XSLT examples
Sample of incoming XML document
Example 1 (transforming XML to XML)
This XSLT stylesheet provides templates to transform the XML document:
Its evaluation results in a new XML document, having another structure:
Example 2 (transforming XML to XHTML)
Example XSLT Stylesheet:
XHTML output that this would produce (whitespace has been adjusted here for clarity):In order for a
web browser to be able to automatically apply an XSL transformation to an XML document, an 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 would be added to the original incoming XML:References
ee also
*
XSLT elements - a list of some commonly used XSLT structures
*XML transformation language - any computer language designed specifically to transform an "input" XML document into an "output" XML document that satisfies some specific goal
*Extensible Stylesheet Language - a family of languages of which XSLT is a member
* XQuery and XSLT compared
*XML template engine - including a list of XSLT processor implementations
*Tree programming
*Identity transform - a starting point for filter chains that add or remove data elements from XML trees in a transformation pipeline
*Apache Cocoon - a Java-based framework for processing data with XSL and other transformers.
*Omnimark - another structured text processing language (and a proprietary software)External links
; For implementations, see
XML template engine .; Documentation
* [http://www.w3.org/TR/xslt XSLT 1.0 W3C Recommendation]
* [http://www.w3.org/TR/xslt20/ XSLT 2.0 W3C Recommendation]
* [http://www.dpawson.co.uk/xsl XSLT Frequently Asked Questions]
* [http://zvon.org/xxl/XSLTreference/Output/index.html Zvon XSLT 1.0 Reference]
* [http://www.nwalsh.com/docs/tutorials/xsl/xsl/ XSL Concepts and Practical Use] by Norman Walsh
* [http://www-106.ibm.com/developerworks/xml/library/x-hands-on-xsl/index.html?dwzone=xml Tutorial from developerWorks] byIBM (1 hour)
* [http://zvon.org/xxl/XSLTutorial/Output/index.html Zvon XSLT Tutorial]
* [http://www.w3schools.com/xsl/ XSLT Tutorial] by [http://www.w3schools.com W3 Schools]
* [http://www.brics.dk/~amoeller/XML/transformation/ Quick tutorial]
* [http://www-106.ibm.com/developerworks/xml/library/x-xslt/?article=xr What kind of language is XSLT?]
* [http://www.idealliance.org/papers/xml2001/papers/html/05-03-06.html XSLT and Scripting Languages]
* [http://schema-aware.com schema-aware.com - examples of schema-aware XSLT]; Mailing lists
* [http://www.mulberrytech.com/xsl/xsl-list/ The XSLT mailing list hosted by Mulberrytech]; Books
* "XSLT" by Doug Tidwell, published by O’Reilly (ISBN 0-596-00053-7)
* "XSLT Cookbook" by Sal Mangano, published by O’Reilly (ISBN 0-596-00974-7)
* "XSLT 2.0 Programmer's Reference" by Michael Kay (ISBN 0-764-56909-0)
* "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 and XPath on the Edge (Unlimited Edition)" by Jeni Tennison, published by Hungry Minds Inc, U.S. (ISBN 0-7645-4776-3)
* "XSLT & XPath, A Guide to XML Transformations" by John Robert Gardner and Zarella Rendon, published by Prentice-Hall (ISBN 0-13-040446-2); XSLT code libraries
* [http://www.exslt.org/ EXSLT] is a widespread community initiative to provide extensions to XSLT.
* [http://fxsl.sf.net/ FXSL] is a library implementing support forHigher-order function s in XSLT. FXSL is written in XSLT itself.
* [http://xsltsl.sourceforge.net/ 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.
* [http://kernowforsaxon.sf.net/ Kernow] A GUI for Saxon that provides a point and click interface for running transforms.
* [http://johannburkard.de/software/xsltjs/ xslt.js – Transform XML with XSLT] JavaScript library that transforms XML with XSLT in the browser.; Further examples
* [http://www.mkv25.net/scripts/xslt/xslt-examples.html XSLT Examples using JavaScript] based on wiki examples and [http://www.w3schools.com/xsl/xsl_client.asp w3schools XSLT on the Client]
Wikimedia Foundation. 2010.