<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:key name="sum" match="//@length" use="number(translate(.,':','.'))"/>
<xsl:template match="/">
<xsl:apply-templates select="Specials"/>
</xsl:template>
<xsl:template match="Specials">
<html>
<head>
<title>
<xsl:apply-templates select="Title"/>
</title>
</head>
<body>
<xsl:apply-templates select="CDs"/>
<xsl:call-template name="question789"/>
</body>
</html>
</xsl:template>
<xsl:template match="CDs">
<xsl:apply-templates select="CD"/>
</xsl:template>
<xsl:template match="CD">
<div>
<p>Title: <xsl:value-of select="@title"/></p>
<p>Artist: <xsl:value-of select="./Artist"/></p>
<p>Total Tracks: <xsl:value-of select="count(./Tracks/Track)"/></p>
<xsl:apply-templates select="Tracks"/>
</div>
</xsl:template>
<xsl:template match="Tracks">
<xsl:apply-templates select="Track"/>
<p>
<xsl:call-template name="timesum">
<xsl:with-param name="km" select="child::Track/@length"/>
</xsl:call-template>
</p>
</xsl:template>
<xsl:template match="Track">
<ul>
<li>Track: <xsl:value-of select="."/></li>
<li>Track Length: <xsl:value-of select="@length"/></li>
</ul>
</xsl:template>
<xsl:template name="timesum">
<xsl:param name="km"/>
<xsl:param name="ak" select="1"/>
<xsl:param name="min" select="0"/>
<xsl:param name="hour" select="0"/>
<xsl:variable name="c" select="count($km)"/>
<xsl:choose>
<xsl:when test="$ak <= $c">
<xsl:variable name="tmin" select="substring-after($km[$ak],':')"/>
<xsl:variable name="thour" select="substring-before($km[$ak],':')"/>
<xsl:call-template name="timesum">
<xsl:with-param name="ak" select="$ak+1"/>
<xsl:with-param name="km" select="$km"/>
<xsl:with-param name="hour" select="$hour + $thour"/>
<xsl:with-param name="min" select="$min + $tmin"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('Total duration',$hour+($min -$min mod 60) div 60,':',format-number($min mod 60,'00'))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="question789">
<h1>answer of question 7,8,9</h1>
<p>Track number of ‘All Blues’ song on ‘Kind of Blue’ CD</p>
<p>count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1</p>
<h3>
<xsl:value-of select="count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1"/>
</h3>
<p>Name of second track on ‘Cookin’ CD</p>
<p>/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]</p>
<h3>
<xsl:value-of select="/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]"/>
</h3>
<p>Total cost to purchase all 3 CDs (UK prices)</p>
<p>sum(/Specials/CDs//CD/PriceUK)</p>
<h3>
<xsl:value-of select="sum(/Specials/CDs//CD/PriceUK)"/>
</h3>
</xsl:template>
</xsl:stylesheet>