XSL

Introduction to XSL

Evolution of XML What is XML? The eXtensible Markup Language (XML) is a general-purpose markup language. Its primary purpose is to facilitate the sharing of data across different information systems, particularly via the Internet. It is a simplified subset of the Standard Generalized Markup Language (SGML), and is designed to be relatively human-legible. By adding semantic constraints, application …

Introduction to XSL Read More »

Overview of XSL Transformations

Overview of XSL Transformations In an XSL transformation, an XSLT processor reads both an XML document and an XSLT style sheet. Based on the instructions the processor finds in the XSLT style sheet, it outputs a new XML document or fragment thereof. There’s also special support for outputting HTML. With some effort most XSLT processors can also be made to output essentially arbitrary text, though XSLT is designed primarily for XML-to-XML and XML-to-HTML transformations. Trees Every …

Overview of XSL Transformations Read More »

XSL output methods

Options for displaying XML  XSL output methods <xsl:output cdata-section-elements=”namelist” doctype-public=”string” doctype-system=”string” encoding=”string” indent=”yes” | “no” media-type=”mimetype” method=”html” | “name” | “text” | “xml” omit-xml-declaration=”yes” | “no” standalone=”yes” | “no” version=”version_number” /> The xsl:output element is used to define the format of the output created by the stylesheet. This is accomplished by setting one or more of …

XSL output methods Read More »

What’s with Stylesheets in the first place?

We can even use CSS to format XML, but as we know CSS is designed to format HTML not XML (meta languages) and XML is not like HTML. XML is related with data whereas HTML is used for presentation of the information on the internet. How XML is different from HTML: XML is not a fixed tag set (like HTML) XML by itself has no (application) semantics A generic XML processor has no idea what is …

What’s with Stylesheets in the first place? Read More »

What Does a Stylesheet Do?

A stylesheet specifies the presentation of XML information using two basic categories of techniques: • An optional transformation of the input document into another structure • A description of how to present the transformed information (i.e., a specification of what properties to associate to each of the various parts of the transformed information) As we know, XML does not …

What Does a Stylesheet Do? Read More »

Transformation capabilities

Transformation capabilities include: • generation of constant text • suppression of content • moving text (e.g., exchanging the order of the first and last name) • duplicating text (e.g., copying titles to make a table of contents) • sorting • more complex transformations that “compute” new information in terms of the existing information Description of …

Transformation capabilities Read More »

The components of the XSL

The components of the XSL The full XSL language logically consists of three component languages which are described in three W3C (World Wide Web Consortium) Recommendations: XPath:  XML Path Language–a language for referencing specific parts of an XML document XSLT:  XSL Transformations–a language for describing how to transform one XML document (represented as a tree) into another XSL:  Extensible Stylesheet Language–XSLT plus a description of a …

The components of the XSL Read More »

XSL vs. HTML Formatting Objects

XSL is a W3C Recommendation XSL or CSS is essential for XML presentation and XSL far more powerful and complicated than CSS. XSL permits : • element reordering • selection of source elements • text generation • processing source elements multiple times • Transformation is independent of the target result type • Most people are more familiar with HTML so many of the examples in this tutorial use HTML • …

XSL vs. HTML Formatting Objects Read More »

The Structure of a Stylesheet

The Structure of a Stylesheet • XSLT Stylesheets are XML documents; namespaces (http://www.w3.org/TR/REC-xml-names) are used to identify semantically significant elements. • Most stylesheets are stand-alone documents rooted at <xsl:stylesheet> or <xsl:transform>. It is possible to have “single template” stylesheet/documents. • <xsl:stylesheet> and <xsl:transform> are completely synonymous. Note that it is the mapping from namespace abbreviation to URI that is important, not the literal namespace abbreviation “xsl:” …

The Structure of a Stylesheet Read More »

Match Patterns (Locating Elements)

Match Patterns (Locating Elements) One critical capability of a stylesheet language is to locate source elements to be styled. CSS, for example, does this with “selectors.” FOSIs do it with “e-i-c’s”, elements in context. XSLT does it with “match patterns” defined by the XML Path Language (XPath). XPath has an extensible string-based syntax. It describes “location paths” between parts of a document or …

Match Patterns (Locating Elements) Read More »

More Complex Patterns

section/*/note Matches <note> elements that have <section> grandparents. stockquote[@symbol] Matches <stockquote> elements that have a “symbol” attribute stockquote[@symbol=”XXXX”] Matches <stockquote> elements that have a “symbol” attribute with the value “XXXX“ emphasis|strong Matches <emphasis> or <strong> elements Pattern Syntax The XPath pattern syntax is described formally in the XPath specification. Here we’re going to look at the syntax in abstract, …

More Complex Patterns Read More »

Node Tests & Axis Specifiers

Node Tests & Axis Specifiers Node tests are most frequently element names, but other node tests are possible: name Matches <name> element nodes * Matches any element node namespace:name Matches <name> element nodes in the specified namespace namespace:* Matches any element node in the specified namespace comment() Matches comment nodes text() Matches text nodes processing-instruction() …

Node Tests & Axis Specifiers Read More »

Applying Style

Applying Style One model for applying style is to allow the process to run recursively, driven primarily by the document. A series of templates is created, such that there is a template to match each context, then these templates are recursively applied starting at the root of the document. • <xsl:template> <xsl:template match=”section/title”> <h2><xsl:apply-templates/></h2> </xsl:template> …

Applying Style Read More »

Conflict Resolution

Conflict Resolution The problem of multiple patterns that match is handled by conflict resolution: • Matching templates from imported modules are not considered if there is a matching template in the current module • Matching templates with a lower priority are not considered. The default priority is determined as follows: • Unqualified child or attribute …

Conflict Resolution Read More »

Applying Style Procedurally

Applying Style Procedurally The other model for applying style is to select each action procedurally. A series of templates is created, such that each template explicitly selects and processes the necessary elements. • <xsl:for-each> <xsl:for-each select=”row”> <tr><xsl:apply-templates/></tr> </xsl:for-each> • Named Templates • <xsl:param> <xsl:param name=”type”>warning</xsl:param> • <xsl:call-template> <xsl:call-template name=”admonition”/> • <xsl:with-param> <xsl:call-template name=”admonition”> <xsl:with-param name=”type”>caution</xsl:with-param> …

Applying Style Procedurally Read More »

Named Template Example

Named Template Example namedtemplate.xml <?xml version=”1.0″ encoding=”iso-8859-1″?> <?xml-stylesheet type=”text/xsl” href=”named_temp_example.xsl”?> <chapter> <warning> <para>Using a damaged extension cord may cause a fire.</para> </warning> <caution> <para>Freshly brewed coffee is hot.</para> </caution> </chapter> namedtemplate.xsl <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”html” encoding=”iso-8859-1″ /> <xsl:template name=”admonition”> <xsl:param name=”type”>Warning</xsl:param> <table border=”1″> <tr><th><xsl:value-of select=”$type”/>:</th></tr> <tr><td><xsl:apply-templates/></td></tr> </table> </xsl:template> <xsl:template match=”warning”> <xsl:call-template name=”admonition”/> </xsl:template> <xsl:template …

Named Template Example Read More »

Creating the Result Tree

Creating the Result Tree Literal Result Elements Any element in a template rule that is not in the XSL (or other extension) namespace is copied literally to the result tree <xsl:text> The content of <xsl:text> elements is copied directly to the result tree; whitespace is preserved by default <xsl:text>Literal result text</xsl:text> <xsl:value-of> Inserts the value …

Creating the Result Tree Read More »

Conditional Processing

Conditional Processing The xsl:if element evaluates an expression which returns a Boolean result to determine if a template should be instantiated. The evaluation is a simple True or False test on a defined condition or a set of conditions. If the test returns True, the template is applied and the results are displayed in the output. If False, the template is not applied (i.e., …

Conditional Processing Read More »

Declaring and Using Variables

A variable in XSLT has more in common with a variable in algebra than with a variable in a typical programming language. It’s a name that represents a value and, within a particular application of a template, it will never represent any other value — it can’t be reset using anything described in the XSLTRecommendation. (Some XSLT processors offer a …

Declaring and Using Variables Read More »

Numbering

Numbering The <xsl:number> element performs two functions: It evaluates a numeric expression and converts the result into a formatted string: <xsl:number value=”3″ format=”A. “/><xsl:number value=”count(listitem)” format=”01″/> It counts elements in the source tree and converst the result into a formatted string: <xsl:number count=”listitem” format=”i. “/> <xsl:number count=”chapter” from=”book” level=”any” format=”1. “/> <xsl:number count=”h1|h2|h3″ level=”multiple” from=”chapter|appendix” …

Numbering Read More »

Scroll to Top