Extensible Stylesheet Language Transformations


XSLT ( eXtensible Stylesheet Language Transformations ), defined in the recommendation XSL from the W3C , is an XML transformation language type functional . It makes it possible to transform an XML document into another format, such as PDF or HTML, to be displayed as a web page .

Description

The main goal is to transform an XML document into another schema or format ( XHTML , XSL-FO , HTML , etc.). However, the XSLT language also allows transformations to any other type of document, in text format or in a binary format (although this is not natively foreseen by the XSLT recommendation). Given two entries, an XML document to be transformed and an XSLT document, an XSLT analyzer ( XSLT processor ) produces an output file in the desired format.

XSLT relies on XPath (another part of the XSL recommendation) to designate a part of an XML tree. In practice, the XSLT language is itself expressed as an XML document:

<
Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "2.0" >
<xsl: output method = "xml" Indent = "yes" />
<xsl: template match = "person" >
 <name username = "{@username}" >
 <xsl: value-of select = "name" />
 </ name>
</ xsl: template>
</ Xsl: stylesheet>

One of its main features is to be data-centric. An XSLT must rely on an XML, it is a mandatory pair, and it is only possible to create in XSLT loops browsing data selected by XPath .

Example

Input XML file

<? 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>
+ XSLT Style Sheet

<
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>
Results XML file

<? xml version = "1.0" encoding = "UTF-8"?>
<root>
 <name username = "JS1" > John </ name>
 <name username = "MI1" > Morka </ name>
</ root>

XSLT Analyzer Implementations

  • AltovaXML: by Altova , free implementation of XSLT 1.0 and XSLT 2.0
  • DIXml: A Delphi Library
  • Gestalt: by Colin Paul Adams, implementation in Eiffel of XSLT 2.0
  • Libxslt  (en) : by GNOME , implementation in C XSLT 1.0
  • MSXML DOM : by Microsoft for use in DCOM on Windows and therefore accessible to scripting languages ​​such as vbScript and jScript
  • Php_xsl. Dll : included since PHP 5 1
  • QuiXSLT: by Innovimax and INRIA in Java for XSLT 3.0 with Streaming 2
  • Saxon XSLT  (en) : Michael Kay, Saxon exists in Java for XSLT 1.0 and Java and .Net for XSLT 2.0 (with validation of XML Schema )
  • System.Xml.Xsl: Parallel by Microsoft and Novell for the Different Implementation of the .NET Framework
  • Xalan : by the Apache Foundation , exists in Java , C and Perl and manages XSLT 1.0

References

  1. ↑ http://www.php.net/manual/en/book.xsl.php  [ archive ]
  2. ↑ https://project.inria.fr/quix-tool-suite/quixslt/  [ archive ]