Skip to Main Content
XML Hacks
book

XML Hacks

by Michael Fitzgerald
July 2004
Intermediate to advanced content levelIntermediate to advanced
479 pages
12h 30m
English
O'Reilly Media, Inc.
Content preview from XML Hacks

Understand the Anatomy of an XSLT Stylesheet

Get acquainted with the basic elements of an XSLT stylesheet.

You had a close brush with XSLT in the hack that discussed converting text to XML [Hack #18] , but you didn’t see much more than the stylesheet’s name. Here is the complete stylesheet, time.xsl :

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
<xsl:template match="Import">
 <xsl:apply-templates select="Row"/>
</xsl:template>
   
<xsl:template match="Row">
 <time timezone="{@timezone}">
  <xsl:copy-of select="hour|minute|second"/>
  <xsl:apply-templates select="atomic"/>
 </time>
</xsl:template>
   
<xsl:template match="atomic">
 <xsl:copy>
  <xsl:attribute name="signal">true</xsl:attribute>
 </xsl:copy>
</xsl:template>
   
</xsl:stylesheet>

The Document Element

An XSLT stylesheet has two possible document elements, stylesheet and transform (see line 1). Both have identical attributes; in fact, the only difference between the two is that they have different names, but stylesheet seems more popular with developers than transform.

The version attribute is required. Some XSLT processors support a value of 1.1 or 2.0, in support of those versions of the XSLT specs, but 1.0 is the most commonly used value. (Version 1.1 of XSLT is not and will never be a W3C recommendation, so any support for it is processor-dependent.) The namespace declaration is also required if you want an XSLT processor to recognize the XSLT markup. The namespace name for XSLT 1.0 is http://www.w3.org/1999/XSL/Transform ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XML Schema Complete Reference, The

XML Schema Complete Reference, The

Cliff Binstock, Chris Galtenberg, Mike Wooding, Chris Dix, Mitchell Smith, Dave Peterson
.NET & XML

.NET & XML

Niel M. Bornstein

Publisher Resources

ISBN: 0596007116Supplemental ContentErrata Page