Built-in template rule for text and attribute nodes
2.4.5.4 Built-in template rule for comment and processing instruction nodes
This template does nothing. xsl:template match=comment|processing-instruction2.4.5.5 Built-in template rule for namespace nodes
This template also does nothing. xsl:template match=namespace2.4.6 Top-Level Elements
To this point, we havent actually talked about our source document or how were going to transform it. Were simply setting up some properties for the transform. There are other elements we can put at the start of our stylesheet. Any element whose parent is the xsl:stylesheet element is called a top-level element. Here is a brief discussion of the other top-level elements: xsl:include and xsl:import These elements refer to another stylesheet. The other stylesheet and all of its contents are included in the current stylesheet. The main difference between xsl:import and xsl:include is that a template, variable, or anything else imported with xsl:import has a lower priority than the things in the current stylesheet. This gives you a mechanism to subclass stylesheets, if you want to think about this from an object-oriented point of view. You can import another stylesheet that contains common templates, but any templates in the importing stylesheet will be used instead of any templates in the imported stylesheet. Another difference is that xsl:import can only appear at the beginning of a stylesheet, while xsl:include can appear anywhere. xsl:strip-space and xsl:preserve-space These elements contain a space-separated list of elements from which whitespace should be removed or preserved in the output. To define these elements globally, use xsl:strip-space elements= or xsl:preserve-space elements= . If we want to specify that whitespace be removed for all elements except for greeting elements and salutation elements, we would add this markup to our stylesheet: xsl:strip-space elements= xsl:preserve-space elements=greeting salutation xsl:key This element defines a key, which is similar to defining an index on a database. Well talk more about the xsl:key element and the key function in Section 5.2 in Chapter 5 . xsl:variable This element defines a variable. Any xsl:variable that appears as a top-level element is global to the entire stylesheet. Variables are discussed extensively in Section 4.5 in Chapter 4 . xsl:param This element defines a parameter. As with xsl:variable , any xsl:param that is a top-level element is global to the entire stylesheet. Parameters are discussed extensively in Section 4.4 in Chapter 4 . page 30 Other stuff More obscure elements that can appear as top-level elements are xsl:decimal- format , xsl:namespace-alias , and xsl:attribute-set . All are discussed in Appendix A .2.4.7 Other Approaches
One mantra of the Perl community is, Theres more than one way to do it. Thats true with XSLT stylesheets, as well. We could have written our stylesheet like this: xsl:stylesheet xmlns:xsl=http:www.w3.org1999XSLTransform version=1.0 xsl:output method=html xsl:template match= html body xsl:apply-templates select=greeting body html xsl:template xsl:template match=greeting h1 xsl:value-of select=. h1 xsl:template xsl:stylesheet In this version, we put the wrapper elements for the HTML document in the template for the root element. One of the things you should think about as you build your stylesheets is where to put elements like html and body . Lets say our XML document looked like this instead: ?xml version=1.0? greetings greetingHello, Worldgreeting greetingHey, Yallgreeting greetings In this case, we would have to put the html and body elements in the xsl:template for the root element. If they were in the xsl:template for the greeting element, the output document would have multiple html elements, something that isnt valid in an HTML document. Our updated stylesheet would look like this: xsl:stylesheet xmlns:xsl=http:www.w3.org1999XSLTransform version=1.0 xsl:output method=html xsl:template match= html body xsl:apply-templates select=greetingsgreeting body html xsl:template xsl:template match=greeting h1 xsl:value-of select=. h1 xsl:template xsl:stylesheetParts
» O'Reilly-XSLT-Mastering.XML.Transformati... 2264KB Mar 29 2010 05:03:43 AM
» An XML document must be contained in a single element
» XML declarations Document Type Definitions DTDs and XML Schemas
» Well-formed versus valid documents
» Tags versus elements XML Document Rules
» Namespaces XML Document Rules
» The Extensible Stylesheet Language XSL
» Document Object Model DOM Level 1
» Document Object Model DOM Level 2
» Namespaces in XML XML Standards
» Associating stylesheets with XML documents
» Installing Xalan Getting Started
» Our Sample Document A Sample Stylesheet
» Transforming the XML Document
» Stylesheet Results Transforming Hello World
» Parsing the Stylesheet How a Stylesheet Is Processed
» Parsing the Transformee How a Stylesheet Is Processed
» Lather, Rinse, Repeat How a Stylesheet Is Processed
» The xsl:template for greeting Elements
» Built-in template rule for element and root nodes
» Built-in template rule for modes
» Built-in template rule for text and attribute nodes
» Top-Level Elements Stylesheet Structure
» Other Approaches Stylesheet Structure
» The Hello World Java Program
» Goals of This Chapter Summary
» The Root Node The XPath Data Model
» Element Nodes The XPath Data Model
» Attribute Nodes The XPath Data Model
» Text Nodes The XPath Data Model
» Comment Nodes The XPath Data Model
» Processing Instruction Nodes The XPath Data Model
» Namespace Nodes The XPath Data Model
» Simple Location Paths Location Paths
» Relative and Absolute Expressions
» Selecting attributes Selecting Things Besides Elements with Location Paths
» Selecting the text of an element
» Selecting comments, processing instructions, and namespace nodes
» Using Wildcards Location Paths
» Numbers in predicates Predicates
» Functions in predicates Predicates
» Attribute Value Templates XPath Datatypes
» Output View The XPath View of an XML Document
» The Stylesheet The XPath View of an XML Document
» Summary XPath: A Syntax for Describing Needles and Haystacks
» Converting to boolean values
» Boolean examples The xsl:if Element
» xsl:for-each example The xsl:for-each Element
» How It Works Invoking Templates by Name
» Templates à la Mode Invoking Templates by Name
» Defining a Parameter in a Template
» Microsofts XSLT tools Global Parameters
» Setting global parameters in a Java program
» Are These Things Really Variables?
» Procedural design Implementing a String Replace Function
» Recursive design Implementing a String Replace Function
» Template Design Implementation A Stylesheet That Emulates a for Loop
» The Complete Example A Stylesheet That Emulates a for Loop
» XML Input A Stylesheet That Generates a Stylesheet That Emulates a for Loop
» Template Design A Stylesheet That Generates a Stylesheet That Emulates a for Loop
» Complications A Stylesheet That Generates a Stylesheet That Emulates a for Loop
» Summary Branching and Control Elements
» The ID, IDREF, and IDREFs Datatypes
» An XML Document in Need of Links
» A Stylesheet That Uses the id Function
» Limitations of IDs Generating Links with the id Function
» Defining a key Generating Links with the key Function
» A Slightly More Complicated XML Document in Need of Links
» The key function and the IDREFS datatype
» Solution 1: Replace the IDREFS datatype
» Solution 2: Use the XPath contains function
» Solution 3: Use recursion to process the IDREFS datatype
» Solution 4: Use an extension function
» Advantages of the key Function
» An Unstructured XML Document in Need of Links
» The generate-id Function Generating Links in Unstructured Documents
» Summary Creating Links and Cross-References
» Our First Example Sorting Data with xsl:sort
» Whats the deal with that syntax?
» Attributes The Details on the xsl:sort Element
» Another Example Sorting Data with xsl:sort
» Our First Attempt Grouping Nodes
» A Brute-Force Approach Grouping with xsl:variable
» Summary Sorting and Grouping Elements
» Recursive design An Aside: Doing Math with Recursion
» Generating output to initialize a variable
» Overview Invoking the document Function
» The document Function and Sorting
» Implementing Lookup Tables More Sophisticated Techniques
» Grouping Across Multiple Documents
» Summary Combining XML Documents
» Example: Generating multiple output files
» Example: Using extension functions from multiple processors
» Example: A library of trigonometric functions
» Example: Writing extensions in other languages
» Fallback Processing Extension Elements, Extension Functions, and Fallback Processing
» Extending the Saxon Processor
» Generating JPEG Files from XML Content
» About the Toot-O-Matic Case Study: The Toot-O-Matic
» Make It Easier to Create Tutorials
» Individual Panels Tutorial Layout
» Email Panel Zip File PDF Files
» Individual Panels XML Document Design
» Stylesheets and Modes XSLT Source Code
» Initializing Global Variables XSLT Source Code
» Generating the Main Menu Panel
» Generating the Section Indexes
» Generating the Individual Panels
Show more