HOME

TheInfoList



OR:

XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming
XML 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. T ...
documents into other XML documents, or other formats such as
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaS ...
for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as
PDF Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
,
PostScript PostScript (PS) is a page description language in the electronic publishing and desktop publishing realm. It is a dynamically typed, concatenative programming language. It was created at Adobe Systems by John Warnock, Charles Geschke, Do ...
and PNG. Support for JSON and plain-text transformation was added in later updates to the XSLT 1.0 specification. As of August 2022, 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. 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. Typically, input documents are XML files, but anything from which the processor can build an
XQuery and XPath Data Model 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.Anders Berglund, ''et al.''XQuery 1.0 and XPath 2.0 Data Model W3C, 2010, re ...
can be used, such as
relational database A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relati ...
tables or geographical information systems. While XSLT was originally designed as a special-purpose language for XML transformation, the language is
Turing-complete In computability theory, a system of data-manipulation rules (such as a computer's instruction set, a programming language, or a cellular automaton) is said to be Turing-complete or computationally universal if it can be used to simulate any ...
, making it theoretically capable of arbitrary computations.


History

XSLT is influenced by functional languages, and by text-based pattern matching languages like SNOBOL and AWK. Its most direct predecessor is DSSSL, which did for
SGML The Standard Generalized Markup Language (SGML; ISO 8879:1986) is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on two postulates": * Declarative: Markup should ...
what XSLT does for XML. * XSLT 1.0: XSLT was part of the
World Wide Web Consortium The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working ...
(W3C)'s
eXtensible Stylesheet Language In computing, the term Extensible Stylesheet Language (XSL) is used to refer to a family of languages used to transform and render XML documents. Historically, the W3C XSL Working Group produced a draft specification under the name "XSL," whic ...
(XSL) development effort of 1998–1999, a project that also produced
XSL-FO XSL-FO (XSL Formatting Objects) is a markup language for XML document formatting that is most often used to generate PDF files. XSL-FO is part of XSL (Extensible Stylesheet Language), a set of W3C technologies designed for the transformation and ...
and XPath. Some members of the standards committee that developed XSLT, including James Clark, the editor, had previously worked on DSSSL. XSLT 1.0 was published as a W3C recommendation in November 1999. Despite its age, XSLT 1.0 is still widely used (), since later versions are not supported natively in
web browser A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used o ...
s or for environments like
LAMP Lamp, Lamps or LAMP may refer to: Lighting * Oil lamp, using an oil-based fuel source * Kerosene lamp, using kerosene as a fuel * Electric lamp, or light bulb, a replaceable component that produces light from electricity * Light fixture, or ligh ...
. * XSLT 2.0: after an abortive attempt to create a version 1.1 in 2001, the XSL working group joined forces with the XQuery working group to create XPath 2.0, with a richer data model and type system based on
XML Schema An XML schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself. These constra ...
. Building on this is XSLT 2.0, developed under the editorship of Michael Kay, which reached recommendation status in January 2007. The most important innovations in XSLT 2.0 include: ** String manipulation using regular expressions ** Functions and operators for manipulating dates, times, and durations ** Multiple output documents ** Grouping (creating hierarchic structure from flat input sequences) ** A richer type system and stronger type checking * XSLT 3.0: became a W3C Recommendation on 8 June 2017. The main new features are: ** Streaming transformations: in previous versions the entire input document had to be read into memory before it could be processed, and output could not be written until processing had finished. XSLT 3.0 allows XML streaming which is useful for processing documents too large to fit in memory or when transformations are chained in XML Pipelines. ** Packages, to improve the modularity of large stylesheets. ** Improved handling of dynamic errors with, for example, an xsl:try instruction. ** Support for maps and arrays, enabling XSLT to handle JSON as well as XML. ** Functions can now be arguments to other (higher-order) functions.


Design and processing model

The XSLT processor takes one or more XML source documents, plus one or more XSLT stylesheets, and processes them to produce an output document. In contrast to widely implemented
imperative programming In computer science, imperative programming is a programming paradigm of software that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program ...
languages like C, XSLT is declarative. The basic processing paradigm is pattern matching. 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 Functional may refer to: * Movements in architecture: ** Functionalism (architecture) ** Form follows function * Functional group, combination of atoms within molecules * Medical conditions without currently visible organic basis: ** Functional sy ...
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 In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, including only woody plants with secondary growth, plants that are ...
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.


XPath

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.


XQuery compared

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 The World Wide Web (WWW), commonly known as the Web, is an information system enabling documents and other web resources to be accessed over the Internet. Documents and downloadable media are made available to the network through we ...
(as a web template language), or on paper. XQuery was primarily conceived as a
database query language Query languages, data query languages or database query languages (DQL) are computer languages used to make queries in databases and information systems. A well known example is the Structured Query Language (SQL). Types Broadly, query languages ...
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.


Media types

The <output> element can optionally take the attribute media-type, which allows one to set the
media type A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication o ...
(or MIME type) for the resulting output, for example: . 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 the registration of the MIME media type application/xslt+xml and it was later registered with the
Internet Assigned Numbers Authority The Internet Assigned Numbers Authority (IANA) is a standards organization that oversees global IP address allocation, autonomous system number allocation, root zone management in the Domain Name System (DNS), media types, and other Inte ...
. Pre-1.0 working drafts of XSLT used text/xsl in their embedding examples, and this type was implemented and continues to be promoted by Microsoft in Internet Explorer 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.


Examples

These examples use the following incoming XML document John Smith Morka Ismincius


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: John Morka


Example 2 (transforming XML to XHTML)

Processing the following example XSLT file Testing XML Example

Persons

  • ,
  • with the XML input file shown above results in the following
    XHTML Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages. It mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated. While HTML, prior ...
    ( whitespace has been adjusted here for clarity): Testing XML Example

    Persons

    • Ismincius, Morka
    • Smith, John
    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: In this example, text/xsl is technically incorrect according to the W3C specifications (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.


    Processor implementations

    *RaptorXML from Altova is an XSLT 3.0 processor available in the XMLSpy development toolkit and as a free-standing server implementation, invoked using a REST interface. * IBM offers XSLT processing embedded in a special-purpose hardware appliance under the Datapower brand. *
    libxslt libxslt is the XSLT C library developed for the GNOME project. It provides an implementation of XSLT 1.0, plus most of the EXSLT set of processor-portable extensions functions and some of Saxon's evaluate and expressions extensions. libxslt is ...
    is a free
    library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
    released under the MIT License that can be reused in commercial applications. It is based on
    libxml libxml2 is a software library for parsing XML documents. It is also the basis for the libxslt library which processes XSLT-1.0 stylesheets. Description Written in the C programming language, libxml2 provides bindings to C++, Ch, XSH, C#, Py ...
    and implemented in C for speed and portability. It supports XSLT 1.0 and EXSLT extensions. **It can be used at the command line via xsltproc which is included in
    macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and la ...
    and many Linux distributions, and can be used on
    Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for se ...
    via
    Cygwin Cygwin ( ) is a POSIX-compatible programming and runtime environment that runs natively on Microsoft Windows. Under Cygwin, source code designed for Unix-like operating systems may be compiled with minimal modification and executed. The Cygwin in ...
    . **The
    WebKit WebKit is a browser engine developed by Apple and primarily used in its Safari web browser, as well as on the iOS and iPadOS version of any web browser. WebKit is also used by the BlackBerry Browser, PlayStation consoles beginning from the ...
    and
    Blink Blinking is a bodily function; it is a semi-autonomic rapid closing of the eyelid. A single blink is determined by the forceful closing of the eyelid or inactivation of the levator palpebrae superioris and the activation of the palpebral portio ...
    layout engines, used for example in the
    Safari A safari (; ) is an overland journey to observe wild animals, especially in eastern or southern Africa. The so-called "Big Five" game animals of Africa – lion, leopard, rhinoceros, elephant, and Cape buffalo – particularly form an impor ...
    and Chrome web browsers respectively, uses the libxslt library to do XSL transformations. ** Bindings exist for Python,
    Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
    ,
    Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called ...
    , PHP,
    Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fr ...
    , Tcl, and C++. *
    Microsoft Microsoft Corporation is an American multinational technology corporation producing computer software, consumer electronics, personal computers, and related services headquartered at the Microsoft Redmond campus located in Redmond, Washi ...
    provides two XSLT processors (both XSLT 1.0 only). The earlier processor MSXML provides COM interfaces; from MSXML 4.0 it also includes the command line utility msxsl.exe. The .NET runtime includes a separate built-in XSLT processor in its System.Xml.Xsl library. *
    Saxon The Saxons ( la, Saxones, german: Sachsen, ang, Seaxan, osx, Sahson, nds, Sassen, nl, Saksen) were a group of Germanic * * * * peoples whose name was given in the early Middle Ages to a large country (Old Saxony, la, Saxonia) near the Nor ...
    is an XSLT 3.0 and XQuery 3.1 processor with
    open-source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized so ...
    and
    proprietary {{Short pages monitor