You Too Can Transform Your <body> - Page 7
October 28, 2002
Now we've made sure that transformations will actually happen, we begin defining
the transformations themselves. Further down the stylesheet are some lines
that perform a template transformation on the <body> element of dinosaur_1.xml:
<xsl:template match="body">
<body>
<table style="border: solid thin black">
<tr>
<td><a href="mammoth.html">Visit
the Mammoth zone!</a> - </td>
<td><a href="play.html">Play
Pteranodon Poker</a></td>
</tr>
</table>
<xsl:apply-templates />
<hr/>
Copyright 2002 DinosaurOrg.
</body>
</xsl:template>
The first line of this section tells the XSLT processor to search through
the XML document until it finds the opening tag of a <body> element, and then perform a transformation
on the contents of this <body>
element (everything from <body> to </body>). It's called xsl:template because
its content defines a template for how to transform a <body> element.
The next seven lines are the start of this <body> element template. These lines of HTML
are added in to the transformed page before the content of the original
<body> element. The template
does not do anything with the matched <body> tag itself, and so we insert a <body> tag ourselves in the template.
The start of dinosaur_1.xml is transformed
from
to
<body>
<table style="border: solid thin black">
<tr>
<td><a href="mammoth.html">Visit
the Mammoth zone!</a> - </td>
<td><a href="play.html">Play
Pteranodon Poker</a></td>
</tr>
</table>
...
Our header is successfully added!
About the Stylesheet - Page 6
Practical XML for the Web
Transformation Without Change - Page 8
|