Datasheet
Williams c01.tex V3 - 07/31/2009 2:53pm Page 10
Chapter 1: First Steps with XSLT
It causes the current XML node in the source document to be copied to the output. The actual effect
depends on whether the node is an element, an attribute, or a text node. For an element, the start and
end element tags are copied; the attributes, character content, and child elements are copied only if
xsl:apply-templates
is used within
xsl:copy
.
In contrast, if you use
<xsl:copy-of>
, each new node will contain copies of all the children, attributes,
and namespaces of the original node, recursively. This is often called a deep copy. This instruction has a
select
attribute, providing you with more flexibility in selection:
<xs:element name
=
"copy-of" substitutionGroup
=
"xsl:instruction">
<xs:complexType>
<xs:complexContent mixed
=
"true">
<xs:extension base
=
"xsl:versioned-element-type">
<xs:attribute name
=
"select" type
=
"xsl:expression" use
=
"required"/>
<xs:attribute name
=
"copy-namespaces" type
=
"xsl:yes-or-no" default
=
"yes"/>
<xs:attribute name
=
"type" type
=
"xsl:QName"/>
<xs:attribute name
=
"validation" type
=
"xsl:validation-type"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
Listing 1-3 shows the completed stylesheet. Save this version as
local.xsl
.
Listing 1-3
<?xml version
=
"1.0" encoding
=
"UTF-8"?>
<xsl:stylesheet xmlns:xsl
=
"http://www.w3.org/1999/XSL/Transform"
version
=
"1.0">
<xsl:output method
=
"html"
encoding
=
"UTF-8"
doctype-system
=
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public
=
"-//W3C//DTD XHTML 1.0 Transitional//EN"/>
<xsl:template match
=
"/">
<html>
<head>
<title>
<xsl:value-of select
=
"reference/body/title"/>
</title>
</head>
<body>
<xsl:apply-templates select
=
"reference/body"/>
</body>
</html>
</xsl:template>
<xsl:template match
=
"title">
<h1>
<xsl:value-of select
=
"."/>
</h1>
</xsl:template>
<xsl:template match
=
"purpose">
<h2>Purpose</h2>
<xsl:apply-templates select
=
"p"/>
</xsl:template>
10