XSLT

Template: Infobox file format / Maintenance / Magic number is missing template: Infobox file format / Maintenance / missing site

Template: Infobox file format / Maintenance / Screenshot Format

XSL transformation, short XSLT is a language for transforming XML documents. It is part of the Extensible Stylesheet Language (XSL) and is a turing - complete linguistic fields;

XSLT is based on the logical tree structure of an XML document and is used to define transformation rules. XSLT programs called XSLT stylesheets are constructed it themselves according to the rules of the XML standard.

The stylesheets are of special software, the XSLT processors, read, convert with these instructions, one or more XML documents in the desired output format. XSLT processors are integrated in many modern Web browsers, such as Opera (version 9), Firefox, and Internet Explorer version 5 ( only since version 6 with full XSLT 1.0 support ).

XSLT is a subset of XSL, together with XSL-FO and XPath.

History

Originally created a DSSSL -like language in XML syntax with XSL. However, it soon became clear that such a language actually consists of three interacting but independently deployable components:

  • One language for the description of a document as a tree with markup and style information: XSL Formatting Objects (XSL -FO )
  • One language for the transformation of an arbitrary XML document into another tree, such as an XSL - FO: XSLT
  • A language for addressing parts of trees: XPath

The declarative, functional and applicative language XSLT has emerged among others from DSSSL. XSLT was originally developed by James Clark (XSLT 1.0, XSLT 1.1), for the current development Michael Kay is responsible. Since January 23, 2007 XSLT 2.0 is a " Recommendation" (recommendation ) of the W3C and has the force since 1999 Revision XSLT 1.0 replaced. Meanwhile, a XSLT version 3.0 exists as a Working Draft of December 2010 of the W3C, which has been supported by the commercial versions of the Saxon parser partially.

Operation

The XSLT language describes the transformation of an XML derivative ( also XML dialect or XML application called ), in the form of an XML document into another document, called transformation. The resulting document usually corresponds to the XML syntax, but there may be other text files and even binary files are created.

These XML documents are considered as a logical tree: the source tree to be transformed documents and the products resulting from the transformation of the target trees to be generated documents.

A transformation consists of a series of individual transformation rules, called templates ( German " template "). A template has an XPath -based patterns ( German " pattern " ) that describes for which node it is, and a content which determines how the template generates its part of the target tree.

In an XSLT document that is coming in languages ​​and XML -based technologies at least these steps:

  • XML as the basis for XSLT
  • XSLT itself ( XML - based)
  • XPath / XSLT Patterns
  • The language (s) of the source document (XML - based, such as DocBook )
  • The language (s ) of the target document (often XML - based, such as XHTML (from XSLT 2.0 ), XML, XSLT itself, but also HTML, or RELAX NG, text format also available)
  • XML namespaces to distinguish the languages ​​used

As well as from XSLT 2.0:

  • " XML Schema " data types
  • XHTML

Template Rules and Conflict Resolution

Template Rules ( German "Template Rules" ) are always applied when a certain condition matches. The following example includes the contents of all the titles ("title" tags) in " em" tags, no matter where they occur in the document, and shall not affect the remainder.

           < / em > < / xsl: template> " " Transforms the child elements of the current element by all applicable rules for it.

Conflict Resolution ( German " conflict resolution " ) is required if a node template to several rules match the same time. In such cases, the following rules apply.

  • Imported rules have lower priority.
  • If an attribute is given priority, it is taken into account.
  • More specific patterns have higher priority than less specific. For example, the test of whether any node exists, less specific than a test for a node with a concrete name.
  • If there are multiple equal rules, that is a mistake, and is output from the XSLT parser as a message.

Sorting and conditional output

To sort items, a " for-each " tag can be combined with a "sort" tag. The loop then does not run in the order of the nodes of the original document, but in alphabetical or numerical order. In the following example all book elements are sorted in ascending order according to their price.

   < / xsl: for-each > With or without order = " ascending" the order is always the same (low ) as this is the default setting. With order = " descending" obtained a descending order.

XSLT provides both binary decisions by the "if" tag and multiple decisions on the "choose " tag. The following example returns if and only from an asterisk if the attribute " nationality " of the element "author " has the value "U.S." has.

* < / xsl: if> In order to meet a number of case distinctions, the combination of "choose " can - and "when" tags are used.

   ...    ...    ...    ... < / xsl: choose> Output text unchanged

To hear any text by XSLT, can the tag " " are used, the escaping ( the output of " <" and "&" as "<" and "&") can be turned off. The content can be in plain text or in a CDATA section. The advantage of the CDATA section is that its content is not interpreted, so it can also contain XML syntax.

For example, produces

   > < any text stand # # #] ]> the output:

# # # This may < & >> < any text stand # # # applications

Two important areas of application for XSLT are:

  • POP ( Presentation Oriented Publishing ) is the transformation for the purpose of illustration. With different style sheets, the data in XHTML, Formatting Objects (XSL -FO ), SVG, SMIL, DocBook and many other formats can be converted. The target document must be an XML document, this is not mandatory. The original semantic markup is replaced by a style - related markup.
  • MOM (Message Oriented Middleware ) denotes the transformation for the purpose of data exchange. Because XML is simply a language concept for the development of languages ​​, it is not enough that two systems (eg programs ) XML control to mutually exchange data. You must use the same XML-based language. In the frequent case where the systems do not use the same XML -based language that is often used XSLT to develop with the help of transformations translator from one language to another.

Examples of POP are about:

  • Statistical data as XML are available (eg from the database) and processed using different transformations as Vector graphics in SVG
  • Text
  • Table in XHTML
  • PDF ( via the intermediate step XSL -FO ) or
  • Excel table ( by SpreadsheetML from Office XP).

Alternatives to XSLT

A possible alternative to XSLT is DSSSL, which can also be regarded as a precursor of XSLT. Probably the biggest advantage of XSLT against DSSSL is its XML-based syntax. Thus, any XML editor can be automatically used for XSLT, as well as the syntax rules of XML ( well-formedness, validity ) are thus also for XSLT. Thus, it is possible that XSLT edited themselves, so you can develop transformations for the generation and processing of transformations.

MetaMorphosis

MetaMorphosis is also inspired by DSSSL. In contrast to XSLT, it is a "target driven" (goal -driven ) processor. Here, the aim being created tree is constructed. The rules do not describe how the input file to be processed, but how the output file is to be constructed. The process begins with a virtual control! " Begin" with the process of transformation begins. The transformation rules describe how the nodes are to be filled. Here, queries are formulated in the source trees as well as in the previously constructed target trees. The query language is a set-oriented expression that can read all the properties of the nodes and also set. Generated node can be subsequently manipulated as needed.

Other features of MetaMorphosis support the industrial use: flexible storage management for very large documents, construction of auxiliary data structures ( GetIndex, putindex ) for fast access, plug-in architecture, API for C , C #, Java, the possibility of dedicated front-end and back-end to implement ( in C as well as in the MetaMorphosis scripting language ).

Template Attribute Language

As part of the application server Zope the Template Attribute Language (TAL ) was developed; TAL templates are (depending on output format ) [X ] HTML or XML documents, whose contents can be dynamically replaced by attributes, and thus unite the prototype and used template. The element corresponds to about the attribute tal: repeat; as the expression syntax is used, the TAL Expression Syntax. If offers no HTML or XML element as a carrier of the attribute, even elements can be used.

Programming languages

An important alternative to XSLT is the ability to draft such transformations in any programming language (eg Java, C or Perl). However, XSLT can a certain guarantee for well-formed and may even valid target documents provide for certain requirements are met. In addition, the development of a transformation XSLT is usually associated with substantially less effort than the development of transformation in a programming language.

It is also possible to couple both: the actual transformation happens by XSLT, but user-defined functions are called string manipulation within the XSLT stylesheets. The ( eg, written in Ruby or Python) program then consists of these user-defined functions and calling an XSLT function that takes the style sheet and custom functions as parameters.

CSS

Frequently CSS is mentioned as an alternative to XSLT. However, CSS is only apparently an alternative to XSLT, since it is merely a formatting language with CSS. CSS only describes how the components of a tree (acoustic or visual) must be formatted as XSLT can change radically the tree or as a result can provide documents that are not based on XML. So you can automatically create with XSLT such as tables of contents, indexes, lists of links and complex calculations, but not with CSS. With XSLT, it is also possible to generate results, use the CSS as a formatting language.

Code Example

The following XSLT creates a simple table of contents for an XHTML page with headings:

< xsl: stylesheet      version = "1.0"      xmlns: xsl = " http://www.w3.org/1999/XSL/Transform "      xmlns: html = " http://www.w3.org/1999/xhtml "      xmlns = " http://www.w3.org/1999/xhtml "      exclude-result - prefixes = "html" >        < xsl: output          method = " xml"          doctype-system = " http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd "          doctype-public = " - / / W3C / / DTD XHTML 1.1 / / EN "      / >                                          

< / h1 >             

Table of Contents < / h2 >             

323151
de