120 likes | 243 Vues
This guide covers the essentials of XSLT (Extensible Stylesheet Language Transformation), a powerful language for transforming XML documents. It explains how XSLT operates using the result tree, describes formatting trees and elements, and introduces XPath for pattern description. We'll delve into the structure of XSLT, including templates, for-each statements, and built-in functions for data processing and calculations. Whether you are creating web documents or handling multiple output media types, understanding XSLT will enhance your XML handling capabilities.
E N D
Extensible Style Sheet Language (XSL) • XML application • Style sheet language • Components of the XML document may be rearranged or transformed • One XSL document can support many media output types
Tree Transformations • Performed by XSLT (Extensible Style Sheet Language Transformation) • As XML document is parsed, it is read into memory as the result tree • This tree is used by the browser to write out the formatted document (typically in HTML)
Formatting the Tree • Formatting objects in the tree are considered elements • Developers have control over style and positioning elements • Patterns are applied to make the tree • XPath statements are used to describe the patterns
XSLT Elements • Style sheet declaration • Value of • Template match • For each statements
XSLT Style Sheet Declaration • Defines the document as a XSL Style Sheet • Points to the namespace that controls the sheet • Example for MS Explorer 5.0 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
XSLT Value of • Function that displays data at the current node • Only works with elements with text contained in the tags <xsl:value-of select="."/>
XSL Template Match • Describes which XML elements included in result tree • Describes what to do when these elements are found • Built with XPath statements • First used should match to root • Example shows matching to root and starting an HMTL document
XSL Template Examples <xsl:template match="/"> <html> <head>
XSL For Each Statements • Iteratively walk through similar elements • Very useful when documents have many of the same child elements • Example will print a table of addresses
For Each Example <td><b><i><xsl:value-of select="name"/></i></b></td> <xsl:for-each select="address"> <td> <xsl:value-of select="."/> </td> </xsl:for-each>
Calculation with XSLT • Aggregate functions are available (sum or count) • XPath parameters describe what to calculate <xsl:value-of select="count(//Person/name)"/> • Math calculations available via function