XSLT for Data Manipulation
OK, here we start to get into real XSLT. The control on this page is very similar to the one we used in the previous test. The main exception is the new attribute, TransformSource, which specifies the path to locate our 02DisplayOneElement.xsl, our XSL transform.
<asp:Xml ID="XmlBibliography" runat="server" DocumentSource="XmlResources/Books.xml" TransformSource="Xslt/02DisplayOneElement.xsl" />
Here's the new stuff, this is the XSLT file that we're using. Note that at top, it has the standard XML declaration specifying that this is an XML file, it's version XML 1.0, and uses UTF-8 encoding. It's important to consider this, because it's actually pretty cool. We have a file of data, Books.xml which is written in XML. If we defined the structure of our XML bibliography language we would use a .xsd file and XSD is also an XML language. Now you can see that XSLT is also an XML language. So all three of the most important pieces of this technology, XML, XSD, and XSLT are XML languages so it's relatively easy to learn them all since they are highly related and very similar.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="">
<xsl:template match="/">
<h3>Book Title</h3>
<xsl:for-each select="/Bibliography/item/title">
<xsl:sort select="." />
<p><xsl:value-of select="." /></p>
</xsl:for-each>
<h3>Series Titles</h3>
<xsl:for-each select="/Bibliography/item/seriesName">
<xsl:sort select="." />
<p><xsl:value-of select="." /></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
And here's the output which this generates.
Book Title
Atlas of World History
Breaking the Maya Code
DHTML and CSS Advanced
Flash 8 Accelerated
Flash 8: Graphics, Animation, & Interactivity
Flash 8: Projects for Learning Animation and Interactivity
Gone for Soldiers
Hubble: The Mirror on the Universe
Paris 1919: Six Months That Changed the World
The Crusades Through Arab Eyes
Til We Have Faces
Web Design: Tools and Techniques
Web Designers Reference: An Integrated Approach to Web Design with XHTML and CSS
World Atlas
Writing On Both Sides of the Brain
Series Titles
The Byzantium series
The Lord of the Rings series
The Marcus Didius Falco series
The US Civil War series
The US Revolution series
Skip to Main Points