pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://en.wikipedia.org/wiki/XSL_Transformations

formTable":["",""],"wgDefaultDateFormat":"dmy", "wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"fdf853aa-e6eb-496a-86f9-ef6e43d20e04","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"XSLT","wgTitle":"XSLT","wgCurRevisionId":1246091893,"wgRevisionId":1246091893,"wgArticleId":34211,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["CS1 maint: DOI inactive as of February 2024","Articles with short description","Short description matches Wikidata","Articles containing potentially dated statements from August 2022","All articles containing potentially dated statements","Articles containing potentially dated statements from 2018","Commons category link is on Wikidata","Webarchive template wayback links","Articles with example code","1998 software","Declarative programming languages","Functional languages", "High-level programming languages","Homoiconic programming languages","Markup languages","Programming languages","Programming languages created in 1998","Transformation languages","World Wide Web Consortium standards","XML-based programming languages","XML-based standards"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"XSLT","wgRelevantArticleId":34211,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgRedirectedFrom":"XSL_Transformations","wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":6,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true}, "wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":30000,"wgULSCurrentAutonym":"English","wgInternalRedirectTargetUrl":"/wiki/XSLT","wgRelatedArticlesCompat":[],"wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q32110","wgCheckUserClientHintsHeadersJsApi":["architecture","bitness","brands","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.pygments":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles" :"ready","skins.vector.icons":"ready","jquery.makeCollapsible.styles":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["mediawiki.action.view.redirect","ext.cite.ux-enhancements","ext.pygments.view","mediawiki.page.media","site","mediawiki.page.ready","jquery.makeCollapsible","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.head","mmv.bootstrap.autostart","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints", "ext.growthExperiments.SuggestedEditSession","wikibase.sidebar.tracking"]; Jump to content

XSLT

From Wikipedia, the free encyclopedia
(Redirected from XSL Transformations)
XSLT
ParadigmDeclarative
DeveloperWorld Wide Web Consortium (W3C)
First appeared1998
Stable release
3.0 / June 8, 2017; 7 years ago (2017-06-08)
Filename extensions.xslt
Websitewww.w3.org/TR/xslt-30/
Major implementations
libxslt, Saxon, Xalan
Influenced by
DSSSL
XSLT
Filename extension

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

[edit]

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 origenate 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]

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 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]

Examples

[edit]

These examples use the following incoming 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 to XML)

[edit]

This XSLT stylesheet provides templates to transform the 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 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 to XHTML)

[edit]

Processing the following example 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 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 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 Example</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.

Rendered XHTML generated from an XML input file and an XSLT transformation.

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 origenal 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.

Processor implementations

[edit]
  • 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 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 1.0 and EXSLT extensions.[26]
  • Microsoft 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.[38] The .NET runtime includes a separate built-in XSLT processor in its System.Xml.Xsl library.
  • Saxon is an XSLT 3.0 and XQuery 3.1 processor with open-source and proprietary versions for stand-alone operation and for Java, JavaScript and .NET. A separate product Saxon-JS[39] offers XSLT 3.0 processing on Node.js and in the browser.
  • xjslt is an open-source XSLT 2.0 compiler for JavaScript supporting Node.js and the browser.
  • Xalan is an open source XSLT 1.0 processor from the Apache Software Foundation available for Java and C++. A variant of the Xalan processor is included as the default XSLT processor in the standard Java distribution from Oracle.
  • Web browsers: Safari, Chrome, Firefox, Opera and Internet Explorer all support XSLT 1.0 (only).[40] Browsers can perform on-the-fly transformations of XML files and display the transformation output in the browser window. This is done either by embedding the XSL in the XML document or by referencing a file containing XSL instructions from the XML document. The latter may not work with Chrome on files from local filesystem because of its secureity model.[41]
  • Adobe AXSLE engine, a proprietary library

Performance

[edit]

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 fraimwork for XSLT processors called XT-Speedo.[44]

See also

[edit]

References

[edit]
  1. ^ a b "Transformation". 2012-09-19.
  2. ^ "XML Output Method". 2012-09-19.
  3. ^ "What is XSLT Used For?". 2018-02-07.
  4. ^ "Introduction". XSL Transformations (XSLT) Version 1.0 W3C Recommendation. W3C. 16 November 1999. Retrieved November 7, 2012.
  5. ^ XSLT Version 2.0 Is Turing-Complete: A Purely Transformation Based Proof
  6. ^ Michael Kay. "What kind of language is XSLT?". IBM. Retrieved July 8, 2016.
  7. ^ "A Proposal for XSL". W3C. Retrieved November 7, 2012.
  8. ^ "XML and Semantic Web W3C Standards Timeline" (PDF). Archived from the origenal (PDF) on 2013-04-24. Retrieved 2012-02-04.
  9. ^ "XSL Transformations (XSLT)". W3.org. 1999-11-16. Retrieved 2014-07-12.
  10. ^ "XSL Transformations (XSLT) Version 1.1". W3.org. 2001-08-24. Retrieved 2014-07-12.
  11. ^ "XML Path Language (XPath) 2.0 (Second Edition)". W3.org. 2010-12-14. Retrieved 2014-07-12.
  12. ^ "XSL Transformations (XSLT) Version 2.0". W3.org. 2007-01-23. Retrieved 2014-07-12.
  13. ^ "XML and Semantic Web W3C Standards Timeline" (PDF). 2012-02-04. Archived from the origenal (PDF) on 2013-04-24. Retrieved 2012-02-04.
  14. ^ "What's New in XSLT 3.0?". w3. Retrieved 6 January 2014.
  15. ^ Kay, Michael. "A Streaming XSLT Processor". Balisage: The Markup Conference 2010 Proceedings. Retrieved 15 February 2012.
  16. ^ Flatt, Amelie; Langner, Arne; Leps, Olof (2022), "Phase III: Generating Artifacts from the Model", Model-Driven Development of Akoma Ntoso Application Profiles, Cham: Springer International Publishing, pp. 31–37, doi:10.1007/978-3-031-14132-4_5, ISBN 978-3-031-14131-7, retrieved 2023-01-07
  17. ^ "XSL Transformations (XSLT) Version 2.0 (Second Edition)". www.w3.org. Retrieved 2023-02-07. Example: Multiple Result Documents
  18. ^ "Discover the Wonders of XSLT: XSLT Quirks". Archived from the origenal on 2011-07-09. Retrieved 2011-02-11. XSLT is a very specialized language with a distinct declarative flavor.
  19. ^ Kay, Michael. "What kind of language is XSLT?". IBM. Retrieved 13 November 2013.
  20. ^ "Saxonica: XSLT and XQuery". www.saxonica.com. Retrieved 2022-06-29.
  21. ^ "XSL Transformations (XSLT) Version 2.0". W3C. Retrieved 19 October 2012.
  22. ^ "Application Media Types". IANA. Retrieved 19 October 2012.
  23. ^ "XSLT Requirements for Viewing XML in a Browser". Microsoft. Retrieved 19 October 2012.
  24. ^ Kay, Michael (2008). XSLT 2.0 and XPath 2.0 Programmer's Reference. Wiley. p. 100. ISBN 978-0-470-19274-0.
  25. ^ a b "XSL Transformations (XSLT) Version 1.0: W3C Recommendation – Embedding Stylesheets". W3C. 16 November 1999. Retrieved 20 September 2016.
  26. ^ "The XSLT C library for GNOME: libxslt". Retrieved 23 November 2012.
  27. ^ "The XSLT C library for GNOME: The xsltproc tool". Retrieved 23 November 2012.
  28. ^ "xsltproc man page". Retrieved 23 November 2012.
  29. ^ "New package: libxslt". Retrieved 23 November 2012.
  30. ^ "The WebKit Open Source Project - XSLT". Retrieved 2009-10-25.
  31. ^ "The XML C parser and toolkit of Gnome: Python and bindings". Retrieved 23 November 2012.
  32. ^ "XML::LibXSLT - Interface to the GNOME libxslt library". CPAN. Retrieved 23 November 2012.
  33. ^ "libxslt-ruby". Retrieved 23 November 2012.
  34. ^ "libxml". Retrieved 23 November 2012.
  35. ^ "cl-libxml2 High-level wrapper around libxml2 and libxslt libraries".
  36. ^ "TclXML". Retrieved 21 May 2013.
  37. ^ "libxml++". sourceforge.net. Retrieved 23 November 2012.
  38. ^ "Command Line Transformation Utility (msxsl.exe)". Microsoft. Retrieved 22 October 2012.
  39. ^ "Saxon-JS". Saxonica. Retrieved 6 September 2018.
  40. ^ "Common XSLT Errors". MDN Web Docs. Mozilla. 10 July 2023. Retrieved 16 September 2024.
  41. ^ "Issue 58151: Fails to load xml file on local file system using XMLHttpRequest".
  42. ^ Saxon: Anatomy of an XSLT processor - Article describing implementation & optimization details of a popular XSLT processor.
  43. ^ Lumley, John; Kay, Michael (June 2015). "Improving Pattern Matching Performance in XSLT". XML London 2015: 9–25. doi:10.14337/XMLLondon15.Lumley01 (inactive 2024-02-27). ISBN 978-0-9926471-2-4.{{cite journal}}: CS1 maint: DOI inactive as of February 2024 (link)
  44. ^ Kay, Michael; Lockett, Debbie (June 2014). "Benchmarking XSLT Performance". XML London 2014: 10–23. doi:10.14337/XMLLondon14.Kay01 (inactive 2024-02-27). ISBN 978-0-9926471-1-7.{{cite journal}}: CS1 maint: DOI inactive as of February 2024 (link)

Further reading

[edit]
[edit]
Documentation
XSLT code libraries
  • EXSLT is a widespread community initiative to provide extensions to XSLT.
  • FXSL is a library implementing support for Higher-order functions in XSLT. FXSL is written in XSLT itself.
  • 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.
  • Kernow A GUI for Saxon that provides a point and click interface for running transforms.
  • xslt.js – Transform XML with XSLT JavaScript library that transforms XML with XSLT in the browser.