2 - How to display the entire document using a XSLT script

XML Document
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="iliad.xsl"?>

<document>

<header>
     <title>Iliad</title>
     <book>1.</book>
     <verses>1-7</verses>
     <translator>Lance Jenott</translator>
     <date>
          <month>April</month>
          <year>2004</year>
     </date>
</header>

<poem>
     <line>Sing, oh goddess, about the wrath of Achilles son of Peleus,</line>
     <line>the accursed wrath which cast a myriad of pain upon the Achaeans</line>
     <line>and sent forth many noble souls of heroes to Hades,</line>
     <line>making them prey for dogs and all birds.</line>
     <line>The will of Zeus was fulfilled,</line>
     <line>when, in fact, the two men first parted ways in strife,</line>
     <line>the son of Atreus, ruler of men, and god-like Achilles.</line>
</poem>

</document>
This is the same XML document we saw on the previous page but now with two important lines added at the top:

<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet type="text/xsl" href="iliad.xsl"?>


Lines that begin this way (?xml) are special processing lines for the browser. The first line tells the web browser what version of XML and what character set the document is using. The second line specifies the file-name of the XSLT script which the browser will call in order to process the XML tags. In this example the file-name of the XSLT script is iliad.xsl


XSLT script: iliad.xsl
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">

     <xsl:value-of select="document"/>

</xsl:template>

</xsl:stylesheet>
This simple script is designed to display the entire document. The line <xsl:value-of select="document"/> tells the browser to locate the first <document> tag it finds in the XML file and to output everything between <document> and </document>, which in this example is the entire text. See the RESULTS below.


RESULTS of iliad.xsl
Iliad 1. 1-7 Lance Jenott April 2004 Sing, oh goddess, about the wrath of Achilles son of Peleus, the accursed wrath which cast a myriad of pain upon the Achaeans and sent forth many noble souls of heroes to Hades, making them prey for dogs and all birds. The will of Zeus was fulfilled, when, in fact, the two men first parted ways in strife, the son of Atreus, ruler of men, and god-like Achilles.
Note that the XSLT script ignores all line breaks in the XML file. In following examples you will learn how to add formatting to the XSLT output.