![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - An XML question - calculating time total [Thread Next] Re: An XML question - calculating time totalTo: NULL Date: 3/1/2005 10:55:00 AM
$ saxon time.xml time.xsl
Elapsed Time (hh:mm:ss): 00:07:00
Song 1: title1
Length (hh:mm:ss): 00:02:30
Song 2: title2
Length (hh:mm:ss): 00:02:15
Song 3: title3
Length (hh:mm:ss): 00:02:15
<album>
<general>
<title>My Album</title>
<year>2005</year>
</general>
<content>
<song>
<songTitle>title1</songTitle>
<songLengthInSeconds>150</songLengthInSeconds>
</song>
<song>
<songTitle>title2</songTitle>
<songLengthInSeconds>135</songLengthInSeconds>
</song>
<song>
<songTitle>title3</songTitle>
<songLengthInSeconds>135</songLengthInSeconds>
</song>
</content>
</album>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template name="time">
<xsl:param name="s" select="songLengthInSeconds"/>
<xsl:text>(hh:mm:ss): </xsl:text>
<xsl:variable name="h" select="floor($s div 3600)"/>
<xsl:value-of select="format-number($h,'00')"/>
<xsl:text>:</xsl:text>
<xsl:variable name="m" select="floor(($s - $h * 60) div 60)"/>
<xsl:value-of select="format-number($m,'00')"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="format-number($s - $h*3600 - $m*60,'00')"/>
</xsl:template>
<xsl:template match="song">
Song <xsl:number/>: <xsl:value-of select="songTitle"/>
Length <xsl:call-template name="time"/>
</xsl:template>
<xsl:template match="general">
<xsl:value-of select="Title"/>
Elapsed Time <xsl:text/>
<xsl:call-template name="time">
<xsl:with-param name="s" select="sum(../content/song/songLengthInSeconds)"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
