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!


0
3/1/2005 4:17:06 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
1077 Views

Similar Articles

[PageSpeed] 59

* Uncle Ben wrote in microsoft.public.dotnet.xml:
>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?

Yes, use http://www.w3.org/TR/xpath#function-sum and the other XPath
functions and operators.
-- 
Bj�rn H�hrmann � mailto:bjoern@hoehrmann.de � http://bjoern.hoehrmann.de
Weinh. Str. 22 � Telefon: +49(0)621/4309674 � http://www.bjoernsworld.de
68309 Mannheim � PGP Pub. KeyID: 0xA4357E78 � http://www.websitedev.de/ 
0
bjoern1 (135)
3/1/2005 12:45:06 PM

Uncle Ben wrote:

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

Yes, certainly, you simply need basic math to split up the seconds value 
into hours, minutes, and seconds and then you need to format the output.

Here is an example stylesheet:

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

<xsl:output method="text" />

<xsl:template match="album">
   <xsl:value-of select="general/title" />
   <xsl:text> (</xsl:text>
   <xsl:value-of select="general/year" />
   <xsl:text>)&#13;&#10;</xsl:text>
   <xsl:text>Elapsed Time : </xsl:text>
   <xsl:call-template name="format-seconds">
     <xsl:with-param name="seconds" 
select="sum(content/song/songLengthInSeconds)" />
   </xsl:call-template>
   <xsl:text>&#13;&#10;&#13;&#10;</xsl:text>
   <xsl:apply-templates select="content/song" />
</xsl:template>

<xsl:template match="song">
   <xsl:text>Song </xsl:text>
   <xsl:value-of select="position()" />
   <xsl:text>: </xsl:text>
   <xsl:value-of select="songTitle" />
   <xsl:text>&#13;&#10;</xsl:text>
   <xsl:text>Length : </xsl:text>
   <xsl:call-template name="format-seconds">
     <xsl:with-param name="seconds" select="songLengthInSeconds" />
   </xsl:call-template>
   <xsl:text>&#13;&#10;&#13;&#10;</xsl:text>
</xsl:template>

<xsl:template name="format-seconds">
   <xsl:param name="seconds" />
   <xsl:variable name="seconds-per-hour" select="3600" />
   <xsl:variable name="seconds-per-minute" select="60" />
   <xsl:variable name="hours" select="floor($seconds div 
$seconds-per-hour)" />
   <xsl:variable name="minutes" select="floor(($seconds - $hours * 
$seconds-per-hour) div $seconds-per-minute)" />
   <xsl:variable name="remaining-seconds" select="$seconds - $hours * 
$seconds-per-hour - $minutes * $seconds-per-minute" />
   <xsl:value-of select="format-number($hours, '00')" />
   <xsl:text>:</xsl:text>
   <xsl:value-of select="format-number($minutes, '00')" />
   <xsl:text>:</xsl:text>
   <xsl:value-of select="format-number($remaining-seconds, '00')" />
</xsl:template>

</xsl:stylesheet>

Output is text of the form:

My Album (2005)
Elapsed Time : 00:07:00

Song 1: title1
Length : 00:02:30

Song 2: title2
Length : 00:02:15

Song 3: title3
Length : 00:02:15

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
3/1/2005 12:59:26 PM
Reply:

Similar Artilces:

XML Header
Hi, I have some XML doc loaded in a C# Web Service. XmlDocument doc = new XmlDocument(); doc.LoadXml(myDoc); Code Missing to manipulate header (I would like to replace or manupulate all these XXXXX): <mso-XXXXXX productversion="XXXXXX"> <mso-application progid="XXXXX"?> doc.Save(myNewDoc); Any idea on how to access and manipulate data within the doc header? Thanks vbdev vb6dev2003 wrote: > I have some XML doc loaded in a C# Web Service. > XmlDocument doc = new XmlDocument(); > doc.LoadXml(myDoc); > > Code Missing to manipulate header ...

Time format as hh:mm:ss
When inputing time as above, Excel is thinking it is a Time as AM or PM, but actually it is a lapsed time. How do I get it to do just hh:mm:ss? Without placing in the : each time would be a timesaver as well. Regards, -- Dennis Hi Dennis, Choose another date format from the Format>Cells>Number tab>Time list. If there isn't any without AM/PM, use a Custom format and format as hh:mm:ss (or choose other time settings in Windows International) Actually Excel doesn't know the difference between elapsed time and a point in time. Technically there is no difference; a point...

Newbie Questions
This must be incredibly easy, but I've poked around in most of the chart options I can find and haven't been able to see it. I have a sheet that looks something like: 6/11/05 6/12/05 6/13/05 ... Inventory Totals A 419 431 432 ... B 145 145 144 ... I'm charting only the values in the A row, 419, 434, etc. An appropriate range is shown on the Y axis. I have the X axis formatted as dates, but I get the dates 1/1, 1/2, etc. How do I tie the X axis labels to the dates in my data? Another question: This data will grow indefini...

Transaction keeps downloading even after accepted multiple times
I have a checking account which downloads automatically / updates automatically when I start Microsoft. There is one transaction from 11/12/2007 that downloads every time, even though I have accepted it or matched it with a transaction and it still keeps downloading. What do I do? I called the bank and they say it is a Microsoft problem. Please advise. In microsoft.public.money, Connie wrote: >I have a checking account which downloads automatically / updates >automatically when I start Microsoft. There is one transaction from >11/12/2007 that downloads every time, even tho...

Read XHTML into XML
Hi all, I need to read/parse XHTML aspx pages and look for certain tokens and content. How can I use a XmlTextReader for this? If not, any other ideas? Thanks in advance, JA Reyes. Jose Antonio Reyes wrote: > I need to read/parse XHTML aspx pages and look for certain tokens and > content. How can I use a XmlTextReader for this? If not, any other ideas? If the pages are well-formed XHTML then it is possible to use XmlReader (in .NET 2.0/3.0) or XmlTextReader (in .NET 1.x) to parse the XHTML documents. You can also use the other XML APIs .NET provides so using XPathNavigator and/o...

Licensing question Terminal Services
Hey, I've got the following setup: - Windows SBS 2008 OEM on two machines (one AD/DC and one with the MS SQL 2008 server on it) - Windows Server 2008 Standard on a third machine acting as the Terminal Server I've purchased five TS User CALs and installed them on the TS machine - working, four used. I'm not very sure about two things though. If I buy new TS CALs do I have to buy five CALs for the SBS, too? And if, wouldn't a Windows Server CAL instead of the more expensive SBS CAL be enough? Thank you in advance -- pannal --------------------------...

How to invoke the xml editor?
I installed vs2005 on a new xp pro machine, and installed everything except C++. When I click on a file with a ".xml" extension it is opened with IE. When I click file/Edit with XML Editor, it opens it with Notepad. If I click File/Open With and select XML Editor, it opens it with IE. So, where is the xml editor? Can it be invoked from withing VS? Where? Bill * billsahiker@yahoo.com wrote in microsoft.public.dotnet.xml: >I installed vs2005 on a new xp pro machine, and installed everything >except C++. When I click on a file with a ".xml" extension it is >opened ...

os upgrade questions
The backroom system at one of our stores was still on Windows 98. I wanted to upgrade to to XP sp2. I installed the upgrade but when the system booted up the sql server would not connect. It said that it was not a installed service. After many new grey hairs I was able to unistall the XP and get the system up and running with only 15 minutes to spare before the store opened. Do I need to reinstall the server inorder to do this upgrade? Could someone please give me some assistance on this? I am using the sql version that came with the retail management software. On Jan 12, 9:17...

run-time error when I re-print an Invoice
Hello I am new to RMS and I am trying to figure out the reason of the run-time error every time I try to re-print an invoice or press the journal button. the error will result in terminating my existing application (POS) and the error also says that t"disconnecting from client...) and give me an error numbers. Any help? HI Alex, can you please specific the exact error no so we can help you in better way. actually wanted to know what create error, also do you know how to check the event log in windows OS check the application event log and find what error or what is the reason your...

Range Sum Question
Ok, I have a open question on summing a range. Here is my situation, jus need to know if there is a formula that I can apply to make my lif simple. I have months going across a row (Jan through Dec) and my categorie down the columns. This is current month data and I want to have column off to the right of my data where I can quickly determine th YTD values. Therefore, if I have data from Jan through Sep, and I wan to see what the YTD is through August for my data. Is there a way t have a "key" that I can input into to adjust the sum function to su just though August? Any s...

show XML schema and values
I have an XML document that looks like the following: <record> <Field1>value1</Field1> <Field2>value2</Field2> <Field3>value3</Field3> </record> What I'm aiming to do is to show the data in a report as in the following example: record: Field1 value1 Field2 value2 Field3 value3 The "Field1-3"-elements can have any name, so I'm trying to get a table that has in one result column the element name, and in the second colum...

Immediate Window question
hi a) how can I open the Immediate Window from code? (not <ctrl> G) b) can I 'clear' the Immediate Window from code? (like <ctrl> A, delete) Thank you -- cinnie "cinnie" <cinnie@discussions.microsoft.com> wrote in message news:545437CA-4488-451E-BE7E-B5EC43606102@microsoft.com... > hi > a) how can I open the Immediate Window from code? (not <ctrl> G) > b) can I 'clear' the Immediate Window from code? (like <ctrl> A, delete) > Thank you > -- > cinnie Neither of those actions are available in VBA. Your...

Ex 5.5 question
I currently have an Ex5.5 SP4 server running on a Domain Controller that is part of ForestA/DomainA. I need to demote the domain controller (dcpromo) and then promote it again into it's OWN forest and domain as a standalone DC. The question is what will this do to Exchange 5.5 on the server? (when I re-promote the DC I plan to give it the same computer/domain name). Thanks. Exchange 5.5 is a self contained directory so the act of demotion should have no impact. What ADCs? Do you have any? How are you managing users? You also need to make sure any name resolution for your Exch...

I want to use excel to keep track of my book collection, but I have a question...
Hi, I want to create a database of sorts using excel to keep track of my book collection, but I have a question. Essentially for each book listed on a row I want a column for each of the following: book title, author, publisher, year, and genre. I've used Excel before and have seen a spreadsheet with a worksheet like the above which had a second worksheet that had a button marked "Add book details" When you clicked it you filled the info above into a few boxes and then it would actually add the info you typed in, into the first worksheet and even sorted it into the corr...

Printing questions (partII)
I have this spreadsheet with a calendar for a whole year. Each month is on a separate tab and covers a whole page when printed. I would like these features if they are possible. 1- have a button on each page that prints the actual month (page that is been looked at), and the following month. So if somebody is looking at the month of May, and clicks the button, automatically the June, July, August, Sep... and so on must be printed. This means that the button has to be changed for every month, but that's no problem. I need a macro that prints more than one sheet. 2- this one is tricky: if...

Beginner question #2
Please forgive what might be a beginner question. I have a spread sheet that is made up of 10 columns. I would like to make it so that each time I change a number in these columns, the sub-total at the bottom of each column changes automatically AND so that the sub-total in the far right column changes automatically. Is there a template for this?? Thanks so much!!! You would use a function for that, lets say you have values in A1 to A10, then in A11 place this =SUM(A1:A10), or =A1+A2+A3+A4+A5+A6+A7+A8+A9+A10. got the idea?? "jenny" <jenny@hotmail.net> skrev i melding ne...

Text Formula Question
In COL A, I have a list of 2 and 3 digit charactors. I would like to seperate each string into the three adjacent columns. KQ AJs TT 89s KQ K Q AJs A J s TT T T 89s 8 9 s I know that I can use the Left function for the first col, but cant figure out how to get just the middle or third letters. Thanks in advance, Andrew Check your last post! -- Regards, RD --------------------------------------------------------------------------- Please keep all correspondence within the NewsGroup, so all may benefit ! ------------------------------------------------...

Offline synch using XML web-services
This is a bit long-winded. Can somebody read thru these 2 use cases, and tell me if it is feasible ? :- Use Case : Replication before Offline Synch Scenario 1 : Oracle Server , MSDE client 1. User clicks on 'Go Offline'. System creates a MSDE SQL database in laptop (client), gets the schemas of the tables in Oracle, creates corresponding tables in client's MSDE SQL (mapping Oracle datatypes to SQL datatypes). 2. Offline replication program reads in the tables of the server into a typed datasets, converts the typed datasets into XML, and stores the XML in the client. (XML serial...

Vlookup Question 04-21-10
Hi Every One, I hope you all are doing well, I required your help to resolve my issue in excel. On single worksheet i have two different sheet name as 1.IP Range 2. Result. Question: EG:IP Range Start IP End IP Area 192.168.1.4 195.182.254.254 AG 10.15.33.10 10.18.56.254 EMEA 10.128.33.5 10.132.40.60 AP Here it will Continued as well. On Result sheet i required result like: IP Area 192.170.30.30 AG 194.168.10.20 AG 10.131.37.20 EMEA 10.170.255.255 NA 10.129.36.8 AP I required result on area column. Here we have more than 50000 IP's but very difficul...

stupid question #2
i have a spreadsheet that the last person working on it put last name and first name in the same cell i would like it to have a last name column and a first name column. is it possible to split the contents with out having to retype it all. P.S. there are over 1000 entries ;O) Select the cells with names in and then:- data|text to columns and use the wizard Mike "Kimberly" wrote: > i have a spreadsheet that the last person working on it put last name and > first name in the same cell i would like it to have a last name column and a > first name column. > is it p...

XML Serialization ... how to truncate <?xml...
While xml serializing object how can I truncate <?xml ...?> this line alone? I need to send the serialized xml data to a web method ... since SOAP already have <?xml tag there was some confusion Any help would be greatly appreciated Thank you Regards Raj Raj wrote: > While xml serializing object how can I truncate <?xml ...?> this line alone? Serialize to an XmlWriter created with XmlWriterSettings where you set OmitXmlDeclaration to true. -- Martin Honnen --- MVP XML http://msmvps.com/blogs/martin_honnen/ ...

unauthorized password and security question change
I lost ability to log into my Windows Live hotmail acct last night due to my password being changed without my knowledge. I was not able to reset my password because my security question was also eliminated and an alternative email address that belongs to an unknown person was entered instead. So now I cannot request password info without a total stranger receiving it. I need this fixed and have spent all night trying to find a real person to talk to, to help me with this. I had to set up a second email acct just to engage in this discussion, but it does not help me gain contro...

Eseutil Time to Complete?
My Exchange 2000 mailbox store is now 15GB in size, and I'm going to run eseutil /d on it, to the same drive, as there is plenty of space available. About how long will this take? Any rough estimates would help me schedule offline time. Thanks, -- Bill The ESEUTIL /d will run at a rate of 4GB per hour. I hope this helps. -- Zach ____________ Zachary S. McNelis a-zachm@online.microsoft.com Microsoft PSS Please do not send an email directly to this alias. This is for newsgroup purposes only. This posting is provided "AS IS" with no warranties, and confers no rights. &q...

String to xml document
Hi there, I was hoping someone can help me with a little problem I can't seem to find any answers to. I've got a form wich will be posted. On receiving the post I would like to parse a formvar to a xml document. The contents of this formvar (string) will be a valid xhtml document. Can someone give me a startertip (or more :-)) on how to achieve this? tnx in advance, James van der Veen Sjeems wrote: > I was hoping someone can help me with a little problem I can't seem to find > any answers to. > > I've got a form wich will be posted. On receiving the p...

Re: Noobish question about DBGrid and .mdb files
Sorry I forgot - DBGrid controls are for RDO - DataGrid controls are for ADO - in my experience DataGrid controls are better. "Clive Minnican" <clive@mail.com> wrote in message news:... > You need to create an ADO Data Control first... See the doc below taken from > Visual C++ 6 online help (Using ADO Databinding in Visual C++). I started > off using the DBGrid control but I now prefer to populate a CListCtrl > manually from a CRecordset because you get a lot more control. It's not as > hard as it sounds either - just read up on CDatabase and CRecordset and ...