Paradigm | Declarative |
---|---|
Developer | World Wide Web Consortium (W3C) |
First appeared | 1998 |
Stable release | 3.0 / June 8, 2017 |
Filename extensions | .xslt |
Website | www |
Major implementations | |
libxslt, Saxon, Xalan | |
Influenced by | |
DSSSL |
Filename extension | .xslt |
---|---|
Internet media type | application/xslt+xml |
Uniform Type Identifier (UTI) | org.w3.xsl |
XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, [1] or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG. [2] Support for JSON and plain-text transformation was added in later updates to the XSLT 1.0 specification.
As of August 2022 [update] , the most recent stable version of the language is XSLT 3.0, which achieved Recommendation status in June 2017.
XSLT 3.0 implementations support Java, .NET, C/C++, Python, PHP and NodeJS. An XSLT 3.0 JavaScript library can also be hosted within the web browser. Modern web browsers also include native support for XSLT 1.0. [3]
For an XSLT document transformation, 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 files, but anything from which the processor can build an XQuery and XPath Data Model can be used, such as relational database tables or geographical information systems. [1]
While XSLT was originally designed as a special-purpose language for XML transformation, the language is Turing-complete, making it theoretically capable of arbitrary computations. [5]
XSLT is influenced by functional languages, [6] and by text-based pattern matching languages like SNOBOL and AWK. Its most direct predecessor is DSSSL, which did for SGML what XSLT does for XML. [7]
The XSLT processor takes one or more XML source documents, plus one or more XSLT stylesheets, and processes them to produce one or multiple output documents. [16] [17] In contrast to widely implemented imperative programming languages like C, XSLT is declarative. [18] The basic processing paradigm is pattern matching. [19] 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.
A typical processor behaves as follows. First, assuming a stylesheet has already been read and prepared, the processor builds a source tree from the input 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. Finally the result tree is serialized as XML or HTML text.
XSLT uses XPath to identify subsets of the source document tree and perform calculations. XPath also provides a range of functions, which XSLT itself further augments.
XSLT 1.0 uses XPath 1.0, while XSLT 2.0 uses XPath 2.0. XSLT 3.0 will work with either XPath 3.0 or 3.1. In the case of 1.0 and 2.0, the XSLT and XPath specifications were published on the same date. With 3.0, however, they were no longer synchronized; XPath 3.0 became a Recommendation in April 2014, followed by XPath 3.1 in February 2017; XSLT 3.0 followed in June 2017.
XSLT functionalities overlap with those of 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 include XPath 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 a 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 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. [20]
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 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 1.0 it was not specified how the media-type
values should be used.
With the release of the XSLT 2.0, the W3C recommended in 2007 the registration of the MIME media type application/xslt+xml
[21] and it was later registered with the Internet Assigned Numbers Authority. [22]
Pre-1.0 working drafts of XSLT used text/xsl
in their embedding examples, and this type was implemented and continued to be promoted by Microsoft in Internet Explorer [23] and MSXML circa 2012. 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 were obliged to use this unregistered media type. [24]
These examples use the following incoming XML document:
<?xml version="1.0" ?><persons><personusername="JS1"><name>John</name><family-name>Smith</family-name></person><personusername="MI1"><name>Morka</name><family-name>Ismincius</family-name></person></persons>
This XSLT stylesheet provides templates to transform the XML document:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"><xsl:outputmethod="xml"indent="yes"/><xsl:templatematch="/persons"><root><xsl:apply-templatesselect="person"/></root></xsl:template><xsl:templatematch="person"><nameusername="{@username}"><xsl:value-ofselect="name"/></name></xsl:template></xsl:stylesheet>
Its evaluation results in a new XML document, having another structure:
<?xml version="1.0" encoding="UTF-8"?><root><nameusername="JS1">John</name><nameusername="MI1">Morka</name></root>
Processing the following example XSLT file
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns="http://www.w3.org/1999/xhtml"><xsl:outputmethod="xml"indent="yes"encoding="UTF-8"/><xsl:templatematch="/persons"><html><head><title>TestingXMLExample</title></head><body><h1>Persons</h1><ul><xsl:apply-templatesselect="person"><xsl:sortselect="family-name"/></xsl:apply-templates></ul></body></html></xsl:template><xsl:templatematch="person"><li><xsl:value-ofselect="family-name"/><xsl:text>,</xsl:text><xsl:value-ofselect="name"/></li></xsl:template></xsl:stylesheet>
with the XML input file shown above results in the following XHTML (whitespace has been adjusted here for clarity):
<?xml version="1.0" encoding="UTF-8"?><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>TestingXMLExample</title></head><body><h1>Persons</h1><ul><li>Ismincius,Morka</li><li>Smith,John</li></ul></body></html>
This XHTML generates the output below when rendered in a web browser.
In order for a web browser to be able to apply an XSL transformation to an XML document on display, 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 could be added to the original incoming XML: [25]
<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>
In this example, text/xsl
is technically incorrect according to the W3C specifications [25] (which say the type should be application/xslt+xml
), but it is the only media type that is widely supported across browsers as of 2009, and the situation is unchanged in 2021.
msxsl.exe
. [38] The .NET runtime includes a separate built-in XSLT processor in its System.Xml.Xsl
library.Most early 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 processing APIs (such as JAXP).
Early XSLT processors had very few optimizations. Stylesheet documents were read into Document Object Models and the processor would act on them directly. XPath engines were also not optimized. Increasingly, however, 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 processors called XT-Speedo. [44]
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML.
In computing, the term Extensible Stylesheet Language (XSL) is used to refer to a family of languages used to transform and render XML documents.
In computing, the Java API for XML Processing (JAXP), one of the Java XML application programming interfaces (APIs), provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:
In software, an XML pipeline is formed when XML processes, especially XML transformations and XML validations, are connected.
XForms is an XML format used for collecting inputs from web forms. XForms was designed to be the next generation of HTML / XHTML forms, but is generic enough that it can also be used in a standalone manner or with presentation languages other than XHTML to describe a user interface and a set of common data manipulation tasks.
Saxon is an XSLT and XQuery processor created by Michael Kay and now developed and maintained by the company he founded, Saxonica. There are open-source and also closed-source commercial versions. Versions exist for Java, JavaScript and .NET.
XPath 2.0 is a version of the XPath language defined by the World Wide Web Consortium, W3C. It became a recommendation on 23 January 2007. As a W3C Recommendation it was superseded by XPath 3.0 on 10 April 2014.
eXist-db is an open source software project for NoSQL databases built on XML technology. It is classified as both a NoSQL document-oriented database system and a native XML database. Unlike most relational database management systems (RDBMS) and NoSQL databases, eXist-db provides XQuery and XSLT as its query and application programming languages.
The identity transform is a data transformation that copies the source data into the destination data without change.
In computing, the two primary stylesheet languages are Cascading Style Sheets (CSS) and the Extensible Stylesheet Language (XSL). While they are both called stylesheet languages, they have very different purposes and ways of going about their tasks.
The XQuery and XPath Data Model (XDM) is the data model shared by the XPath 2.0, XSLT 2.0, XQuery, and XForms programming languages. It is defined in a W3C recommendation. Originally, it was based on the XPath 1.0 data model which in turn is based on the XML Information Set.
The Oxygen XML Editor is a multi-platform XML editor, XSLT/XQuery debugger and profiler with Unicode support. It is a Java application so it can run in Windows, Mac OS X, and Linux. It also has a version that can run as an Eclipse plugin.
A web template system in web publishing allows web designers and developers to work with web templates to automatically generate custom web pages, such as the results from a search. This reuses static web page elements while defining dynamic elements based on web request parameters. Web templates support static content, providing basic structure and appearance. Developers can implement templates from content management systems, web application frameworks, and HTML editors.
XSLT defines many elements to describe the transformations that should be applied to a document. This article lists some of these elements. For an introduction to XSLT, see the main article.
XQuery Update Facility is an extension to the XML Query language, XQuery. It provides expressions that can be used to make changes to instances of the XQuery 1.0 and XPath 2.0 Data Model.
XPath is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) in 1999, and can be used to compute values from the content of an XML document. Support for XPath exists in applications that support XML, such as web browsers, and many programming languages.
XQuery is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats. The language is developed by the XML Query working group of the W3C. The work is closely coordinated with the development of XSLT by the XSL Working Group; the two groups share responsibility for XPath, which is a subset of XQuery.
A processing instruction (PI) is an SGML and XML node type, which may occur anywhere in a document, intended to carry instructions to the application.
An XML transformation language is a programming language designed specifically to transform an input XML document into an output document which satisfies some specific goal.
Zorba is an open source query processor written in C++, implementing
Example: Multiple Result Documents
XSLT is a very specialized language with a distinct declarative flavor.
{{cite journal}}
: CS1 maint: DOI inactive as of November 2024 (link){{cite journal}}
: CS1 maint: DOI inactive as of November 2024 (link)