Programming and Coding
What is the difference between XSL and XSLT?
XML documents have structure but no format. Extensible Stylesheet Language (XSL) adds formatting to XML documents.
XSL is a family of recommendations for defining XML document transformation and presentation. It consists of three parts:
Informally, abbreviation "XSL" often refers to XSLT only, since the latter is in wider use. Also informally XSLT often refers to both XSLT itself and XPath, since most of XSLT document use XPath expressions.
The XSL specification defines XSL as a language for expressing stylesheets. Given a class of arbitrarily structured XML documents or data files, designers use an XSL stylesheet to express their intentions about how that structured content should be presented; that is, how the source content should be styled, laid out, and paginated in a presentation medium, such as a window in a Web browser or a hand-held device, or a set of physical pages in a catalog, report, pamphlet, or book. Formatting is enabled by including formatting semantics in the result tree.
Formatting semantics are expressed in terms of a catalog of classes of formatting objects. The nodes of the result tree are formatting objects. The classes of formatting objects denote typographic abstractions such as page, paragraph, table, and so forth.
Finer control over the presentation of these abstractions is provided by a set of formatting properties, such as those controlling indents, word and letter spacing, and widow, orphan, and hyphenation control. In XSL, the classes of formatting objects and formatting properties provide the vocabulary for expressing presentation intent.
XSLT (Extensible Stylesheet Language Transformations) is a declarative, XML-based language used for the transformation of XML documents into other XML documents. An XSLT stylesheet specifies the presentation of a class of XML documents by describing how an instance of the class is transformed into an XML document that uses a formatting vocabulary, such as (X)HTML or XSL-FO.
The XSLT processing model involves:
The XSLT processor is provided with two tree structures to walk through. The first is the structure for the source XML document and the second is the XSLT document itself. After these two structures are provided, the XSLT processor attempts to match element or attribute names found in the XML document with templates contained in the XSLT tree structure. This matching process uses XPath expressions that are embedded within the XSLT document. When a node found within the XML document matches a template in the XSLT document, that template is processed.
Processing of templates found within an XSLT document normally starts with a template that matches the root node of the XML document and proceeds down to its children. When a template is processed, the output is added to the third tree structure mentioned earlier that is used in building the output document.
When we write XSLT stylesheets, we’ll use XSLT which defines a set of primitives used to describe a document transformation to tell the processor what to do, and we’ll use XPath which defines a syntax for describing locations in XML documents to tell the processor what document to do it to.
The general structure of an XSLT stylesheet looks like this:
<!-- optional top-level elements, such as: -->
<!-- set of template rules: -->
The document, or root, element of the stylesheet is xsl:stylesheet. Alternatively, you can use the xsl:transform element, which behaves exactly the same way. Which you use is a matter of personal preference. The XSLT namespace is http://www.w3.org/1999/XSL/Transform. The conventional namespace prefix is xsl, but any prefix can be used—provided that it binds to the XSLT namespace URI.
Here’s an XSLT stylesheet that defines how to transform the XML document:
<!-- greeting.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform">
It can transform the following XML document into something we can view in an ordinary household browser:
<!-- greeting.xml -->
if you’re using Microsoft’s MSXSL, type this command:
msxsl greeting.xml greeting.xsl -o greeting.html
This command transforms the document greeting.xml, using the templates found in the stylesheet greeting.xsl. The results of the transformation are written to the file greeting.html.
© 2020 Digcode.com. All rights reserved.