<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output method="html" indent="yes" />

<!-- This is a step-by-step XSLT walkthrough, from Day 2 of the June 2002 ARL Workshop (Web Development with XML: Design and Application). This stylesheet can be applied to moremusic.xml. To test any step, simply remove the comment markings (remember that you CANNOT nest one comment within another).  -->

<!-- STEP 1: a template that matches the root node; does nothing
<xsl:template match="/">
</xsl:template>
 -->

<!-- STEP 2: matches the root node; prints boilerplate
<xsl:template match="/">
    Hello World!
</xsl:template> 
-->

<!-- STEP 3: same as STEP 2, but with HTML boilerplate 
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    Hello World!
	</body>
    </html>
</xsl:template> 
-->

<!-- STEP 4: same as STEP 3, but with an apply-templates element to process the rest of the tree  
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    <xsl:apply-templates />
	</body>
    </html>
</xsl:template> 
-->

<!-- STEP 5: same as STEP 4, but with a second template to format the title elements (the two <h2> lines are equivalent in this case) 
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    <xsl:apply-templates />
	</body>
    </html>
</xsl:template> 

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
   <h2><xsl:value-of select="." /></h2>
</xsl:template>
-->

<!-- STEP 6:  same as STEP 5, but the root element has been modified to select only title elements and suppress output of everything else; the two lines within <body> are equivalent in this case
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    <xsl:apply-templates select="MYMUSIC/album/title"/>
	    <xsl:apply-templates select="//title"/>
	</body>
    </html>
</xsl:template> 

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
</xsl:template>
--> 

<!-- STEP 7: from root node, each album is selected, then an album template selects title, artist, and year produced
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    <xsl:apply-templates select="MYMUSIC/album"/>
	</body>
    </html>
</xsl:template> 

<xsl:template match="album">
    <xsl:apply-templates select="title"/>
    <i><xsl:value-of select="artist"/></i><br/> 
    <xsl:value-of select="year_produced"/> 
</xsl:template>

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
</xsl:template>
-->

<!-- STEP 8: same as STEP 7, but an sort element has been added to the root template 
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    <xsl:apply-templates select="MYMUSIC/album">
		<xsl:sort select="year_produced"/>
	    </xsl:apply-templates>
	</body>
    </html>
</xsl:template> 

<xsl:template match="album">
    <xsl:apply-templates select="title"/>
    <i><xsl:value-of select="artist"/></i><br/> 
    <xsl:value-of select="year_produced"/> 
</xsl:template>

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
</xsl:template>
-->

<!-- STEP 9: same as STEP 8, but a for-each element has been added to the album template to create an ordered list of song titles 
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
	    <xsl:apply-templates select="MYMUSIC/album">
		<xsl:sort select="year_produced"/>
	    </xsl:apply-templates>
	</body>
    </html>
</xsl:template> 

<xsl:template match="album">
    <xsl:apply-templates select="title"/>
    <i><xsl:value-of select="artist"/></i><br/> 
    <xsl:value-of select="year_produced"/> 
    <ol>
	<xsl:for-each select="song_list/song">
		<li><xsl:value-of select="."/></li>
	</xsl:for-each>
    </ol> 
</xsl:template>

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
</xsl:template>
-->

<!-- STEP 10: same as STEP 9, but the root template has been modified to select only the album with a certain unique id (note that the sort is inconsequential now)
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
    	<xsl:apply-templates select="MYMUSIC/album[@id='DylanBob-1966-1']">
		<xsl:sort select="year_produced"/>
	</xsl:apply-templates>
	</body>
    </html>
</xsl:template> 

<xsl:template match="album">
    <xsl:apply-templates select="title"/>
    <i><xsl:value-of select="artist"/></i><br/> 
    <xsl:value-of select="year_produced"/> 
    <ol>
	<xsl:for-each select="song_list/song">
		<li><xsl:value-of select="."/></li>
	</xsl:for-each>
    </ol> 
</xsl:template>

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
</xsl:template>
-->

<!-- STEP 11: same as STEP 10, but uses expanded XPath syntax to describe some of the nodes
    <html>
	<head><title>My Music</title></head>
	<body>
    	<xsl:apply-templates select="MYMUSIC/child::album[attribute::id='DylanBob-1966-1']">
		<xsl:sort select="year_produced"/>
	</xsl:apply-templates>
	</body>
    </html>
</xsl:template> 

<xsl:template match="album">
    <xsl:apply-templates select="child::title"/>
    <i><xsl:value-of select="child::artist"/></i><br/> 
    <xsl:value-of select="child::year_produced"/> 
    <ol>
	<xsl:for-each select="child::song_list/child::song">
		<li><xsl:value-of select="self::node()"/></li>
	</xsl:for-each>
    </ol> 
</xsl:template>

<xsl:template match="title">
   <h2><xsl:apply-templates /></h2>
</xsl:template>
-->

<!-- STEP 12: the root template selects the song Sway, and the song template displays the title and then reaches up the node tree to grab the name of the album on which the song appears
<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
    	<xsl:apply-templates select="//song[text()='Sway']"/> 
	</body>
    </html>
</xsl:template> 

<xsl:template match="song">
	<b><xsl:value-of select="."/></b><br/>
 	Appears on: <i><xsl:value-of select="ancestor::album/child::title"/></i>
</xsl:template> 
-->

<!-- STEP 13: enough already!! 

<xsl:template match="/">
    <html>
	<head><title>My Music</title></head>
	<body>
    	<xsl:apply-templates select="//song_list"/> 
	</body>
    </html>
</xsl:template> 

<xsl:template match="song_list">
  <xsl:for-each select="song">
  <xsl:if test="text()='Sway'">
	<b><xsl:value-of select="."/></b><br/>
 	is track number <xsl:value-of select="position()"/> on <i><xsl:value-of select="ancestor::album/child::title"/></i>
  </xsl:if>
  </xsl:for-each>
	</xsl:template> 
-->

</xsl:stylesheet>
