Questions tagged [xslt]

XSLT is a transformation language for XML designed to transform structured documents into other formats (such as XML, HTML, and plain text, or, in XSLT 3, JSON). Questions should use one of the xslt-1.0, xslt-2.0, or xslt-3.0 tags as appropriate.

XSLT


News: As of June the 8th, 2017, XSLT 3.0 is a Recommendation of the W3C Consortium


Extensible Stylesheet Language Transformations (XSLT) is a programming language for transforming XML documents into other XML documents, text documents, or HTML documents. Other output formats are possible (e.g., PDF transformations using XSL-FO).

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 can be used, for example, relational database tables, or geographical information systems.

A typical transformation is accomplished as follows:

  1. A stylesheet is created (typically a .xsl file).
  2. An XML data source is created (such as a .xml file).
  3. The XSLT processor is loaded with both the XSL and XML content.
  4. The XML document is parsed into an XPath Data Model (XDM) tree (XDM is similar to DOM).
  5. The XDM tree is traversed to produce a resulting document.

XSLT syntax is based on XML, which means that XSL documents also are well-formed XML documents. XSLT, with a heavy emphasis on recursion, borrows principles from functional languages, including declarative programming, pattern matching, and immutable variables.

As XSL is written in an XML format, its verbosity does not make it the first choice for general-purpose programming. When used correctly, XSL transformations produce elegant solutions to complex problems that are harder to solve in imperative languages.

XSLT Processors and Libraries

XSLT 3.0 processors

XSLT 3.0 processors are backward compatible with XSLT 2.0 and usually XSLT 1.0 as well

  • Saxon provides free and commercial XSLT 1.0, 2.0 and 3.0 command line processors and libraries
  • Raptor XML is Altova's XML and XBRL processor, which as of 2017 supports XSLT 1.0, 2.0 and XSLT 3.0 except streaming. A free command line version used to exist but is no longer available for download.

XSLT 2.0 processors

Backward compatibility with XSLT 1.0 is optional, but most processors support this

XSLT 1.0 processors

An incomplete list of known and lesser known XSLT 1.0 processors:

  • XT, the very first XSLT 1.0 processor by James Clark, still available for download
  • Xalan-Java is a free XSLT 1.0 processor for Java
  • Xalan-C is a free XSLT 1.0 processor for C++
  • System.Xml.Xsl contains Microsoft's managed .NET XSLT 1.0 processor
  • MSXML contains Microsoft's native ActiveX XSLT 1.0 processor, used in versions of Internet Explorer
  • xsltc is a commandline processor to create compiled .NET assemblies for XSLT 1.0 transformations, not to be confused with Xalan's xsltc
  • xsltproc or libxslt is a C library for XSLT 1.0 for the GNOME project, this version is used by PHP and other languages that compile to C
  • TransforMiiX is Mozilla Firefox's XSLT 1.0 processor, of which a stand-alone version can be build.
  • Sablotron an XSLT 1.0 processor written in C++
  • Minoru XSL or MDC-XSL an XSLT 1.0 processor written in C++, seems to be abandoned
  • Xsltp.pl, an XSLT 1.0 compliant processor written natively in Perl
  • XML::XSLT a Perl module with a partial complete XSLT 1.0 processor
  • CFX XSLT open source XSLT 1.0 processor for ColdFusion
  • XSLJIT by DataPower, a hardware accelerated XSLT processor, now used in WebSphere with XA35

JavaScript XSLT 2.0 processors

These processors enable XSLT 2.0 in the browser.

  • Frameless is a light-weight, partial XSLT 2.0 implementation of XSLT in JavaScript for use in the browser
  • Saxon CE is Saxon's XSLT 2.0 processor cross-compiled to JavaScript for use in the browser
  • XSLTy is a command line version of Saxon-CE and supports XSLT 2.0; it requires PhantomJS
  • jQuery XPath 2.0 plugin, while not an XSLT processor, it enables the use of XPath 2.0 from within jQuery, and therefore from within the browser, which is of interest to a large group of users.

JavaScript XSLT 3.0 processors

These processors enable XSLT 3.0 in the browser.

  • Saxon-JS effectively supersedes Saxon-CE. It is an XSLT 3.0 run-time written in pure JavaScript. It executes stylesheets that must be compiled by Saxon-EE directly, or from within an environment such as the oXygen XML editor that includes Saxon-EE.

JavaScript wrappers for XSLT 1.0 in the browser

  • JAXP is the Java API for XML, required when doing transformations in Java through the transformer factory
  • 4XSLT, part of 4Suite is an open source command-line processor for XSLT 1.0, used on Unix systems, see manpage
  • xslt.js is an open source XSLT 1.0 wrapper for transformations in the browser
  • Sarissa is a reliable open source XSLT 1.0 and XML wrapper for transformations in a browser

Tools and libraries

Various libraries and tools include:

  • EXSLT, semi-standardized set of XSLT 1.0 extension functions and instructions
  • FXSL, an XSLT 1.0 and XSLT 2.0 and 3.0 compatible library of a large set of functions
  • xslt-sb, a large set of XSLT 2.0 functions, extensive documentation in German
  • DocBook XSL a large set of XSLT stylesheets to render DocBook XML for PDF, HTML or e-Book
  • FunctX is a large set of XQuery and XSLT 2.0 functions
  • XSLT Standard Library provides a large set of commonly used XSLT 1.0 functionality
  • XTC Unit testing in XSLT and XQuery
  • Kernow is a free user interface to run multiple stylesheets and sources with Saxon 9.x
  • IronXSLT for supporting XSLT intellisense in older Visual Studio versions (it newer versions, XSLT 1.0 intellisense is incorporated)
  • Register fix for Visual Studio 2008 XSLT intellisense
  • Calabash is an implementation of XProc, a standardizes XML pipeline language, used for multiple steps processing of XML
  • EXPath is a collaborative effort to define XPath (and therefore XSLT) extensions including a ZIP Facility, handling binary data, HTTP module etc. It evolved from EXSLT 2.0.
  • SOAP and HTTP extensions for Saxon
  • [XmlSpectrum] 75 is a syntax-highlighter for XSLT/XPath 3.0 - coded in XSLT
  • See further a list of tools using XPath or based on XSLT-related technologies

History

XSLT was proposed by the W3C and has three standards: 1.0 in 1999, 2.0 in 2007 and 3.0 which was published 2017.

Question Tags

Questions should use one of the , , or tags as appropriate to clarify what XSLT version the question requires or references. If you are unsure which version your processor supports, you can check it with XSLT using <xsl:value-of select="system-property('xsl:version')"/>, for instance, by running the stylesheet (self-referencing XML and XSLT) https://martin-honnen.github.io/xslt/processorTest3.xml through your processor.

XSLT Editors

Offline editors

  • oXygen XML Editor (), cross-platform XML editor with enhanced XSLT and XQuery support including a powerful debugger and performance profiler
  • Stylus Studio is an XML, XQuery and XSD editor including XSLT support.
  • Altova is a graphical user interface to design mappings between XML files to create XSLT by drag and drop.
  • Liquid XML allows you to debug XSLT and design XSLT and XML graphically
  • EditiX is an XML editor with support for XSD, XSLT 1.0, 2.0 and 3.0 and comes with a debugger and profiler

Online editors

Resources

Online Training Courses

  1. Foundations of XSLT 2 and XSLT 1 -- A Pluralsight course by Dimitre Novatchev
  2. The Evolution of XPath: What’s New in XPath 3.0 -- A Pluralsight video-course (4.5h)
  3. "What's New in XSLT 3.0: Part 1" -- A Pluralsight video-course (5.5h), by Dimitre Novatchev
35843 questions
449
votes
23 answers

XSLT equivalent for JSON

Is there an XSLT equivalent for JSON? Something to allow me to do transformations on JSON like XSLT does to XML.
luvieere
  • 35,580
  • 18
  • 120
  • 178
332
votes
14 answers

Check if a string is null or empty in XSLT

How can I check if a value is null or empty with XSL? For example, if categoryName is empty? I'm using a when choosing construct. For example:
raklos
  • 26,260
  • 55
  • 172
  • 278
221
votes
12 answers

How to insert   in XSLT

How can I insert   Into an XSLT stylesheet, I keep getting this error: XML Parsing Error: undefined entity Essentially I want a non breaking space character in the XSLT Template.
JL.
  • 71,902
  • 119
  • 298
  • 446
209
votes
10 answers

XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)

I'm trying to create a website that can be downloaded and run locally by launching its index file. All the files are local, no resources are used online. When I try to use the AJAXSLT plugin for jQuery to process an XML file with an XSL template (in…
Kevin Herrera
  • 2,921
  • 3
  • 17
  • 13
206
votes
6 answers

XPath find if node exists

Using a XPath query how do you find if a node (tag) exists at all? For example if I needed to make sure a website page has the correct basic structure like /html/body and /html/head/title.
EddyR
  • 6,561
  • 7
  • 40
  • 50
205
votes
12 answers

Producing a new line in XSLT

I want to produce a newline for text output in XSLT. Any ideas?
Mithil
  • 3,432
  • 10
  • 28
  • 40
195
votes
4 answers

How to apply an XSLT Stylesheet in C#

I want to apply an XSLT Stylesheet to an XML Document using C# and write the output to a File.
Daren Thomas
  • 61,662
  • 38
  • 143
  • 192
194
votes
10 answers

Error: The processing instruction target matching "[xX][mM][lL]" is not allowed

This error, The processing instruction target matching "[xX][mM][lL]" is not allowed occurs whenever I run an XSLT page that begins as follows:
Java Player
  • 6,050
  • 26
  • 99
  • 154
189
votes
4 answers

Is there any way to do a "Replace Or Insert" using web.config transformation?

I'm using web.config transformation as described in the below post in order to generate configs for different environments. http://vishaljoshi.blogspot.com/2009/03/web-deployment-webconfig-transformation_23.html I can do a "Replace" transformation…
Chris Haines
  • 6,207
  • 5
  • 47
  • 61
189
votes
5 answers

XPath with multiple conditions

What XPath can I use to select any category with a name attribute specified and any child node author with the value specified. I've tried different variations of the path below with no success: //quotes/category[@name='Sport' and author="James…
mjroodt
  • 2,833
  • 5
  • 19
  • 35
182
votes
5 answers

How to implement if-else statement in XSLT?

I am trying to implement an if -else statement in XSLT but my code just doesn't parse. Does anyone have any ideas? date:…
Funky
  • 11,511
  • 32
  • 93
  • 157
156
votes
1 answer

Getting the value of an attribute in XML

How would one get the value of attribute1 (blah) in the following xml using xslt:
Dallas
  • 17,186
  • 21
  • 64
  • 82
151
votes
1 answer

XSLT getting last element

I am trying to find the last element in my xml, which looks like:
Nik
  • 7,782
  • 6
  • 54
  • 79
142
votes
19 answers

Pretty printing XML with javascript

I have a string that represents a non indented XML that I would like to pretty-print. For example: should become: Syntax highlighting is not a requirement. To tackle the problem I first transform the…
Darin Dimitrov
  • 960,118
  • 257
  • 3,196
  • 2,876
136
votes
12 answers

Set HTML5 doctype with XSLT

How would I cleanly set the doctype of a file to HTML5 via XSLT (in this case with collective.xdv) The following, which is the best my Google foo has been able to find:
Jon Hadley
  • 5,042
  • 6
  • 37
  • 64
1
2 3
99 100