The Structure of a Stylesheet

The Structure of a Stylesheet
XSLT Stylesheets are XML documents; namespaces ( 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:” that is used most commonly.
A Stylesheet
<xsl:stylesheet xmlns:xsl=”” version=”1.0″>

A Transformation Sheet
<eg:transform xmlns:eg=”” version=”1.0″>

Document as Stylesheet
<html xmlns:xsl=””>
<title>Silly Example</title>
<h1>Silly Example</h1>
<p>You’d probably use extension elements, or somthing more interesting in real life: 3+4 is <xsl:value-of select=”3+4″/>. </p>
XML document for city entity
<?xml version="1.0" encoding="UTF-8"?>


    Document:  city.xml


<cities xmlns:xsi=''












XML stylesheet for city entity
<?xml version="1.0" encoding="UTF-8"?>


     Document:  city2.xsl


    <xsl:stylesheet version="1.0"


    <xsl:output method="xml" encoding="utf-8" indent="yes" />

    <xsl:attribute-set name="date">

       <xsl:attribute name="year">2004</xsl:attribute>

       <xsl:attribute name="month">03</xsl:attribute>

       <xsl:attribute name="day">19</xsl:attribute>


        <xsl:template match="tourGuide">

        <xsl:processing-instruction name="xsl-stylesheet"> 
 href="style.css" type="text/css"<br />


        <xsl:comment>This is a list of the cities
 we are visiting this week</xsl:comment>

           <xsl:for-each select="city">


<!-- element name creates a new element where the
 value of the attribute <tt>name</tt> sets name of 

the new element.  Multiple attribute sets can
 be used in the same element -->


<!-- use-attribute-sets attribute adds all the
 attributes declared in attribute-set from above -->

               <xsl:element name="cityList"  use-attribute-sets="date">

                   <xsl:element name="city">

                         <xsl:attribute name="country">

                         <xsl:apply-templates select="country"/>  </xsl:attribute>

                         <xsl:apply-templates select="cityName"/>


                   <xsl:element name="details">Will write up a 
one page report of the trip</xsl:element>




• Although the output method is set to “xml“, since there is no <html> element as the root of the result tree, it would default to XML output.
• attribute-set is a top-level element that creates a group of attributes by the name of “date.” This attribute set can be reused throughout the stylesheet. The element attribute-set also has the attribute use-attribute-sets allowing you to chain together several sets of attributes.
• The processing-instructionproduces the XML stylesheet processing instructions.
• The element comment creates a comment in the result tree
• The attribute element allows you to add an attribute to an element that is created in the result tree.
Scroll to Top