XSL Transformations (XSLT)

Information Systems and the World Wide Web

International School of New Media
University of Lübeck

Erik Wilde, UC Berkeley School of Information
2007-01-10
Creative Commons License

This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 2.5 License.

Abstract

Because XML can be used to represent any vocabulary (often defined by some schema), the question is how these different vocabularies can be processed and maybe transformed into something else. This something else may be another XML vocabulary (a common requirement in B2B scenarios), or it may be HTML (a common scenario for Web publishing). Using XSL Transformations (XSLT), mapping tasks can be implemented easily. XSLT leverages XPath's expressive power in a rather simple programming language, the programs are often called stylesheets. For easy tasks, XSLT mappings can be specified without much real programming going on, by simply specifying how components of the source markup are mapped to components of the target markup.

XPath and XSLT

  <xsl:for-each select=".//a">
   <xsl:if test="not(@title)">
    <xsl:text>This link has no title!</xsl:text>
   </xsl:if>
  </xsl:for-each>

  <xsl:for-each select=".//a[not(@title)]">
   <xsl:text>This link has no title!</xsl:text>
  </xsl:for-each>

XSLT Executive Summary

XSLT as a Programming Language

Outline (Simple Examples)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

My First XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</xsl:stylesheet>

Why does it Work?

My Second XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="/ | *">
  <xsl:text>( Element: </xsl:text>
  <xsl:value-of select="local-name()"/>
  <xsl:apply-templates select="@* | *"/>
  <xsl:text>)</xsl:text>
 </xsl:template>

 <xsl:template match="@*">
  <xsl:text>Attribute: </xsl:text>
  <xsl:value-of select="local-name()"/>
 </xsl:template>

</xsl:stylesheet>

How does it Work?

My Third XSLT

 <xsl:output method="html"/>
 <xsl:template match="/">
  <html>
   <head>
    <title>Address List</title>
   </head>
   <body>
    <table>
     <xsl:for-each select="/people/entry">
      <tr>
       <td><xsl:value-of select="name/pre[1]"/></td>
       <td><xsl:value-of select="name/sur"/></td>
       <td><a href="mailto:{email}"><xsl:value-of select="email"/></a></td>
      </tr>
     </xsl:for-each>
    </table>
   </body>
  </html>
 </xsl:template>

How Mappings Work

Hello World in XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="/">
  <xsl:text>Hello World!</xsl:text>
 </xsl:template>

</xsl:stylesheet>

Outline (XSLT Instructions)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

XSLT is RISC

Iterations

     <xsl:for-each select="/people/entry">
      <tr>
       <td><xsl:value-of select="name/pre[1]"/></td>
       <td><xsl:value-of select="name/sur"/></td>
       <td><a href="mailto:{email}"><xsl:value-of select="email"/></a></td>
      </tr>
     </xsl:for-each>

Conditional Instructions

My Third XSLT (II)

    <table>
     <xsl:for-each select="/people/entry">
      <tr>
       <td><xsl:value-of select="name/pre[1]"/></td>
       <td><xsl:value-of select="name/sur"/></td>
       <td>
        <xsl:if test="email">
         <a href="mailto:{email}"><xsl:value-of select="email"/></a>
        </xsl:if>
       </td>
      </tr>
     </xsl:for-each>
    </table>

My Third XSLT (III)

       <td>
        <xsl:for-each select="phone">
         <xsl:text>☎ (</xsl:text>
         <xsl:choose>
          <xsl:when test="@location = 'office'">Office</xsl:when>
          <xsl:when test="@location = 'home'">Home</xsl:when>
         </xsl:choose>
         <xsl:text> </xsl:text>
         <xsl:choose>
          <xsl:when test="@type = 'voice'">phone</xsl:when>
          <xsl:when test="@type = 'fax'">fax</xsl:when>
         </xsl:choose>
         <xsl:text>): </xsl:text>
         <xsl:value-of select="."/>
         <xsl:if test="position() ne last()">
          <br/>
         </xsl:if>
        </xsl:for-each>
       </td>

Outline (XSLT Processing Model)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

XSLT Programming

Input and Output

Outline (Templates)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Templates as Building Blocks

Basic Mechanics

  1. The source node list contains only the root node
  2. The result tree is created by inserting the result from processing a node from the source node list
  3. Processing typically puts more nodes on the source node list
  4. The process is repeated until the source node list is empty
 <xsl:template match="/ | *">
  <xsl:text>( Element: </xsl:text>
  <xsl:value-of select="local-name()"/>
  <xsl:apply-templates select="@* | *"/>
  <xsl:text>)</xsl:text>
 </xsl:template>

 <xsl:template match="@*">
  <xsl:text>Attribute: </xsl:text>
  <xsl:value-of select="local-name()"/>
 </xsl:template>

Template Selection

Patterns

Pattern-Based Processing

    <ul>
     <xsl:for-each select="/people/entry">
      <li>
       <xsl:value-of select="concat(name/pre[1], ' ', name/sur, ': ')"/>
       <xsl:apply-templates select="*[local-name() != 'name']"/>
      </li>
     </xsl:for-each>
    </ul>
   </body>
  </html>
 </xsl:template>
 <xsl:template match="email">
  <a href="mailto:{.}" title="{.}">✉</a>
  <xsl:text> </xsl:text>
 </xsl:template>
 <xsl:template match="phone">
  <a href="tel:{.}" title="{@location}/{@type}:{.}">☎</a>
  <xsl:text> </xsl:text>
 </xsl:template>
 <xsl:template match="affiliation"/>

Outline (Built-In Templates)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

XSLT Default Behavior

Root and Elements

 <xsl:template match="* | /">
  <xsl:apply-templates/>
 </xsl:template>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</xsl:stylesheet>

Text and Attributes

 <xsl:template match="text() | @*">
  <xsl:value-of select="."/>
 </xsl:template>

Processing Instructions and Comments

 <xsl:template match="processing-instruction() | comment()"/>

Outline (Conflict Resolution)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Template Selection

Template Selection

  1. All templates with a match attribute
  2. All templates with the same mode
    • part of the apply-templates instruction selecting the node
  3. The Pattern must match
  4. If more than one template matches, order by import precedence
    • the import tree of the stylesheet is considered (this includes the built-in rules)
  5. If more than one template matches, order by priority
    • this sorts rules according to the specificity
  6. Execute resulting rule
    • if still more than one, signal error or execute last in stylesheet

Import Precedence

Priorities

Different Conflicts

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <xsl:apply-templates select="descendant::a"/>
 </xsl:template>
 <xsl:template match="*"/>
 <xsl:template match="a"/>
 <xsl:template match="b/a"/>
 <xsl:template match="c/b/a"/>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<c>
 <b>
  <a/>
 </b>
</c>

Resolution Process

Pattern Priority Resolution Step Manual
Adjustment
1 2 3 4 5
Built-in: text() | @*
Built-in: * | /
* -0.5
a 0.0
b/a 0.25
c/b/a 0.25 priority="1"

Adjusting Priorities

Outline (How to Iterate)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Processing Nodes in XSLT

Homogeneous Processing

Heterogeneous Processing

Outline (Calling Templates)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Executing Templates

Named Templates

Outline (Variables and Parameters)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Programming Language Basics

<xsl:variable name="sum" select="$op1 + $op2"/>
<xsl:variable name="result" select="$sum * $factor"

Outline (Variables)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Why Variables?

Scope and Extent

Using Variables

 <xsl:variable name="name" select="'value'"/>
 <xsl:template match="/">
  <xsl:choose>
   <xsl:when test="$name = 'value'">
    <xsl:variable name="result" select="'ok'"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:variable name="result" select="'problem'"/>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="$result"/>
 </xsl:template>
 <xsl:variable name="name" select="'value'"/>
 <xsl:template match="/">
  <xsl:variable name="result">
   <xsl:choose>
    <xsl:when test="$name = 'value'">
     <xsl:value-of select="'ok'"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="'problem'"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:value-of select="$result"/>
 </xsl:template>

Outline (Parameters)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Parameters vs. Variables

Stylesheet Parameters

 <xsl:param name="number" select="0"/>
 <xsl:variable name="number-param">
  <xsl:if test="string(number($number)) = 'NaN'">
   <xsl:message terminate="yes">"number" must be a proper number!</xsl:message>
  </xsl:if>
  <xsl:value-of select="$number"/>
 </xsl:variable>
 <xsl:template match="/">
  <xsl:value-of select="10 * $number-param"/>
 </xsl:template>

Template Parameters

main param start = 1 ; param count = 10 ; {
	loop (0) };
loop param counter ; {
	print $start + $counter ;
	if ( $counter < $count - 1) then 
		loop ($counter + 1) ; }

Parameter Passing

 <xsl:param name="start" select="1"/>
 <xsl:param name="count" select="10"/>
 <xsl:template match="/">
  <xsl:call-template name="loop">
   <xsl:with-param name="counter" select="0"/>
  </xsl:call-template>
 </xsl:template>
 <xsl:template name="loop">
  <xsl:param name="counter"/>
  <xsl:message>
   <xsl:value-of select="$start + $counter"/>
  </xsl:message>
  <xsl:if test="$counter &lt; $count - 1">
   <xsl:call-template name="loop">
    <xsl:with-param name="counter" select="$counter + 1"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>

Message Facility

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="message" select="'plain'"/>
    <!-- messaging style: 'silent', 'plain', or 'prefixed' -->
    <xsl:template name="message">
        <xsl:param name="level" select="'fatal'"/>
        <!-- message level: 'warning', 'error', or 'fatal' -->
        <xsl:param name="text" select="'no text given'"/>
        <xsl:choose>
            <xsl:when test="$message = 'silent'"/>
            <xsl:when test="$level = 'warning'">
                <xsl:call-template name="print_message">
                    <xsl:with-param name="level" select="'warning'"/>
                    <xsl:with-param name="terminate" select="'no'"/>
                    <xsl:with-param name="text" select="$text"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$level = 'error'">
                <xsl:call-template name="print_message">
                    <xsl:with-param name="level" select="'error'"/>
                    <xsl:with-param name="terminate" select="'no'"/>
                    <xsl:with-param name="text" select="$text"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$level = 'fatal'">
                <xsl:call-template name="print_message">
                    <xsl:with-param name="level" select="'fatal'"/>
                    <xsl:with-param name="terminate" select="'yes'"/>
                    <xsl:with-param name="text" select="$text"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="print_message">
                    <xsl:with-param name="level" select="'fatal'"/>
                    <xsl:with-param name="terminate" select="'no'"/>
                    <xsl:with-param name="text" select="concat('fatal:unknown level for message [', $text, ']')"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="print_message">
        <!-- this template should never be called from outside; for printing messages, call the "message" template. -->
        <xsl:param name="level"/>
        <xsl:param name="terminate"/>
        <xsl:param name="text"/>
        <xsl:choose>
            <xsl:when test="$message = 'plain'">
                <xsl:message terminate="{$terminate}">
                    <xsl:value-of select="$text"/>
                </xsl:message>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate="{$terminate}">
                    <xsl:value-of select="concat($level, ':', $text)"/>
                </xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Outline (Controlling Documents)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

XSLT Processing Model

Outline (Input Documents)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Opening Documents

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="/">
  <xsl:text>me: </xsl:text>
  <xsl:value-of select="count(document('document.xsl')/descendant::*)"/>
  <xsl:text>&#xa;http://dret.net/netdret/publications: </xsl:text>
  <xsl:value-of select="count(document('http://dret.net/netdret/publications')/descendant::*)"/>
 </xsl:template>
</xsl:stylesheet>

Whitespace in Documents

Controlling Whitespace

 <xsl:strip-space elements="*"/>
 <xsl:preserve-space elements="xsl:text"/>
 <xsl:template match="/">
  <xsl:text>xsl:text is used for outputting text.</xsl:text>
  <xsl:text> </xsl:text>
  <xsl:text>it also is the only element where whitespace nodes in the stylesheet are significant</xsl:text>
  <xsl:text>&#xa;</xsl:text>
  <xsl:value-of select="count(//text())"/>
 </xsl:template>

Outline (Output Documents)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Serialization

Multiple Output Documents

Outline (Keys)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Document Access

Declaring and Using Keys

XML and XSLT for using a Key

<people>
 <entry id="dret" country="de">
  <name>
   <pre>Erik</pre>
   <pre>Thomas</pre>
   <sur>Wilde</sur>
  </name>
  <email>dret@berkeley.edu</email>
  <affiliation country="us">iSchool/UCB</affiliation>
  <phone location="office" type="voice">+1-510-6432253</phone>
  <phone location="office" type="fax">+1-510-6425814</phone>
 <xsl:key name="preNameKey" match="name" use="pre"/>
 <xsl:key name="affiliationKey" match="affiliation" use="."/>
 <xsl:key name="countryKey" match="entry | affiliation" use="@country"/>

XSLT Key Structure

preNameKey
Node Value
[1] Erik Thomas Wilde Erik
[1] Erik Thomas Wilde Thomas
[2] Thomas Plagemann Thomas
[3] Bob Glushko Bob
countryKey
Node Value
[1a] Erik Thomas Wilde de
[1b] iSchool/UCB us
[2a] Thomas Plagemann de
[2b] IFI/UIO no
[3a] Bob Glushko us
[3b] iSchool/UCB us

Using Keys

Node Set Intersection

$a[count(. | $b) = count($b)]: Find all nodes in $a where the cardinality of $b does not change when adding this node to it. This means the node must be in $b, and it is in $a to start with.

Outline (Generating Result Nodes)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Literal Result Elements

Producing Nodes Explicitly

 <xsl:template match="*">
  <xsl:element name="{translate(local-name(), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')}">
   <xsl:apply-templates select="node() | @*"/>
  </xsl:element>
 </xsl:template>
 <xsl:template match="@*">
  <xsl:attribute name="{translate(local-name(), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')}">
   <xsl:value-of select="."/>
  </xsl:attribute>
 </xsl:template>

Outline (Modularizing Stylesheets)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

Including and Importing

Import Precedence

Outline (Conclusions)

  1. Simple Examples [7]
  2. XSLT Instructions [5]
  3. XSLT Processing Model [18]
    1. Templates [5]
    2. Built-In Templates [4]
    3. Conflict Resolution [7]
  4. How to Iterate [3]
  5. Calling Templates [2]
  6. Variables and Parameters [9]
    1. Variables [3]
    2. Parameters [5]
  7. Controlling Documents [6]
    1. Input Documents [3]
    2. Output Documents [2]
  8. Keys [6]
  9. Generating Result Nodes [2]
  10. Modularizing Stylesheets [2]
  11. Conclusions [1]

XSLT in Practice