473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

An XML question - calculating time total

I would like to produce the following output based on my XML file:

My Album (2005)
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>

=====

I need some help in designing the XSLT file. I'd like the
<songLengthInSeconds> to be formatted in hh:mm:ss format. Also, I want to
display the elapsed time (in hh:mm:ss format) based on a total of
<songLengthInSeconds>. Could I perform this summation inside the XSLT?

Thank you very much!

Jul 20 '05 #1
3 2612


$ 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>

Jul 20 '05 #2
Please try this XSL..

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

<xsl:output method="text"/>

<xsl:template match="/album">
<xsl:apply-templates select="general" />
<xsl:apply-templates select="content/song" />
</xsl:template>

<xsl:template match="general">
<xsl:value-of select="title" /> (<xsl:value-of select="year"
/>)<xsl:text>&#xA;</xsl:text>
<xsl:variable name="elapsed-time">
<xsl:call-template name="format-time">
<xsl:with-param name="x"
select="sum(following-sibling::content[1]/song/songLengthInSeconds)"
/>
</xsl:call-template>
</xsl:variable>
Elapsed Time (hh:mm:ss): <xsl:value-of select="$elapsed-time"
/><xsl:text>&#xA;</xsl:text>
</xsl:template>

<xsl:template match="content/song">
Song 1: <xsl:value-of select="songTitle"
/><xsl:text>&#xA;</xsl:text>
<xsl:variable name="length">
<xsl:call-template name="format-time">
<xsl:with-param name="x" select="songLengthInSeconds" />
</xsl:call-template>
</xsl:variable>
Length (hh:mm:ss): <xsl:value-of select="$length"
/><xsl:text>&#xA;</xsl:text>
</xsl:template>

<xsl:template name="format-time">
<xsl:param name="x" />

<xsl:value-of select="format-number(floor(($x div 60) div 60),'00')"
/>:<xsl:value-of select="format-number(floor(($x div 60) mod
60),'00')" />:<xsl:value-of select="format-number($x mod 60,'00')" />
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

"T-Narg" <tn***@untouchable.net> wrote in message news:<38*************@individual.net>...
I would like to produce the following output based on my XML file:

My Album (2005)
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>

=====

I need some help in designing the XSLT file. I'd like the
<songLengthInSeconds> to be formatted in hh:mm:ss format. Also, I want to
display the elapsed time (in hh:mm:ss format) based on a total of
<songLengthInSeconds>. Could I perform this summation inside the XSLT?

Thank you very much!

Jul 20 '05 #3
Works well! Thank you very much.

"Mukul Gandhi" <mu**********@yahoo.com> wrote in message
news:b1**************************@posting.google.c om...
Please try this XSL..

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

<xsl:output method="text"/>

<xsl:template match="/album">
<xsl:apply-templates select="general" />
<xsl:apply-templates select="content/song" />
</xsl:template>

<xsl:template match="general">
<xsl:value-of select="title" /> (<xsl:value-of select="year"
/>)<xsl:text>&#xA;</xsl:text>
<xsl:variable name="elapsed-time">
<xsl:call-template name="format-time">
<xsl:with-param name="x"
select="sum(following-sibling::content[1]/song/songLengthInSeconds)"
/>
</xsl:call-template>
</xsl:variable>
Elapsed Time (hh:mm:ss): <xsl:value-of select="$elapsed-time"
/><xsl:text>&#xA;</xsl:text>
</xsl:template>

<xsl:template match="content/song">
Song 1: <xsl:value-of select="songTitle"
/><xsl:text>&#xA;</xsl:text>
<xsl:variable name="length">
<xsl:call-template name="format-time">
<xsl:with-param name="x" select="songLengthInSeconds" />
</xsl:call-template>
</xsl:variable>
Length (hh:mm:ss): <xsl:value-of select="$length"
/><xsl:text>&#xA;</xsl:text>
</xsl:template>

<xsl:template name="format-time">
<xsl:param name="x" />

<xsl:value-of select="format-number(floor(($x div 60) div 60),'00')"
/>:<xsl:value-of select="format-number(floor(($x div 60) mod
60),'00')" />:<xsl:value-of select="format-number($x mod 60,'00')" />
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

"T-Narg" <tn***@untouchable.net> wrote in message

news:<38*************@individual.net>...
I would like to produce the following output based on my XML file:

My Album (2005)
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>

=====

I need some help in designing the XSLT file. I'd like the
<songLengthInSeconds> to be formatted in hh:mm:ss format. Also, I want to display the elapsed time (in hh:mm:ss format) based on a total of
<songLengthInSeconds>. Could I perform this summation inside the XSLT?

Thank you very much!

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MT | last post by:
Hi, I have an invoicing system using postgresql. Each time a customer makes a purchase, a new record is inserted into the "cart" table. The "cart" table, among other things, contains a customer_id...
3
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to...
2
by: dath | last post by:
Hi, Not really a programmer here, but have been forced into the role. I was asked to develop a basic time sheet for employees to enter time. I developed the Table without a problem. I then...
10
by: Lisa | last post by:
In translating the formula for calculating lottery odds for various conditions into a Visual Basic Program, I have apparently missed something in that I get errors in the part of the calculation...
3
by: jbosrock | last post by:
Hi to all, Please bear with me as I am newly experienced in basic Access 2003 only. I don't know Visual Basic or macros at all but am attempting to learn on my own. Explanation: Our fleet...
6
by: richbneal | last post by:
I really like the site so far and this is my first post. I have looked through some of the archives with no luck. I have also read the posting guidelines and will do my best to be clear and accurate...
3
rcollins
by: rcollins | last post by:
I ahve a database that I put together to keep track of the office supplies. We input what has been purchased and what goes out. When I run a report, usually it is just for a month, but I have a...
4
by: Missionary2008 | last post by:
Thank you in advance for your help. I'm trying to calculate the Total Time in hours and minutes to complete a job. The way we are calculating it is by taking the Fee paid and dividing that by a...
21
ddtpmyra
by: ddtpmyra | last post by:
There's two text box that has to enter the the numbers from the user and below I want to display the total value the user inputed. How can I sum it up and have it displayed every they enter a...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.