3.1 - How to display one line of text using <xsl:value-of>

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

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

</xsl:template>
</xsl:stylesheet>
The key command here is <xsl:value-of select="document/poem/line"/>
The information in quotes ("document/poem/line") is called the XPath, that is, the path within the XML tag structure of the document (however the owner has structured it). This command tells the script to locate and display the first instance of a <line> tag found within the <document> and <poem> tags. Thus the script displays the first line of the poem. See the RESULTS below.
[Review the XML document]


RESULTS of iliad02.xsl
Sing, oh goddess, about the wrath of Achilles son of Peleus,


3.2 - How to display multiple lines of text using <xsl:for-each>

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

<xsl:for-each select="document/poem/line">
     <xsl:value-of select="current()"/>
     <br></br>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>
Similar to the <xsl:value-of> command above, <xsl:for-each select="document/poem/line"> tells the browser to locate each instance of a <line> tag found within the XPath document/poem

<xsl:value-of select="current()"/>
As the script sequentially locates each instance of a tag throughout the document, this command tells the script to display the current instance of the <line> tag.

We also told the browser to insert the HTML formatting tags <br></br> between each line in order to keep each line seperate in the display. See the RESULTS below.
[Review the XML document]


RESULTS of iliad03.xsl
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.