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
1218 Views

Similar Articles

[PageSpeed] 52

* 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:

Header Control Notification question
Hi, I created a class called CMyHeaderCtrl which subclass the CHeaderCtrl class. I wish to handle the HDN_TRACK notification message. So I added the following code: MyHeaderCtrl.h: afx_msg void OnTrack(NMHDR *pNMHDR, LRESULT* pResult); MyHeaderCtrl.cpp: BEGIN_MESSAGE_MAP(CMyHeaderCtrl, CHeaderCtrl) //{{AFX_MSG_MAP(CMyHeaderCtrl) //}}AFX_MSG_MAP ON_NOTIFY_REFLECT(HDN_TRACK,OnTrack) END_MESSAGE_MAP() void CMyHeaderCtrl::OnTrack(NMHDR *pNMHDR, LRESULT* pResult) { AfxMessageBox("Track"); ... } The message is not shown when I try dragging the divider. However, if I change ON_N...

Total Purchases in Customer record incorrect
My individual customers Purchase History are all wrong. They don't add up and can't figure what can be done to fix it. It appears that it is doubling the sales, but i can't be sure. It is wrong in Store Ops and HQ. Please advise if there is a fix for this. -- Thanks, joel We found a bug a while ago where customer accounts were being messed up in a hq environment due to date formats being different throughout the stores. I am not sure if this is what is causing your problem but it might be something you want to check on and there is a hotfix released for it. "Joel Ric...

Excel Send to Question
I have Office XP and I would like to be able to send Excel documents by Outlook Express. But when I go into Internet Properties/Programs, the only email listed is Microsoft Outlook. Does anyone know how to add Outlook Express to the E-Mail Listing? Thanks. Anita Anita It should be listed, that's strange. Try opening Outlook Express and going to Tools - Options. On the General tab there should be a button to make OE the default. Hit that button and see if it does the trick. -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Anita" ...

XML and Excel
Hi, I am not familiar with Excel 2003's XML capabilities and looking for more information. Is there a book or website somewhere that will provide some introductory materials on this subject? I am particularly interested in Excel's exporting and importing capabilities of XML files. Thanks in advance, VT There's information on the Microsoft site, for example: http://msdn.microsoft.com/office/understanding/xmloffice/default.aspx http://support.microsoft.com/?kbid=288215 vtisix wrote: > Hi, > > I am not familiar with Excel 2003's XML capabilities and lookin...

XML Encryption
Dear All, I need to do the following to an xml file in vb.net. - Read in the file - canonicalise (c14n) the XML document - generate a 160-bit binary secure hash from the canonicalise XML using the SHA-1 algorithm - encode the binary data using base-64 to produce a 28 character string Can anyone provide me with some help ? I'm very stuck on this. -- Cheers Dave string s = "<Hello>There</Hello>"; SHA1 sha1 = SHA1.Create(); byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(s)); Debug.WriteLine("Hash bytes...

XmlResolver implementation for OASIS XML Catalogs?
Hi, Is there an implementation of System.Xml.XmlResolver for OASIS XML Catalogs (http://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html)? thanks, - Gerben Abbink ...

XML generated from a Dataset with a Relationship established
Hi, I have a dataset with two tables (Order, Item) and a relationship setup to join the tables. I have the nested property of the DataRelation class set to true. When I use the GetXML method the XML looks like this: <Orders> <Order> <OrderID>1</OrderID> <Item> <ItemID>1</ItemID> </Item> <Item> <ItemID>2</ItemID> </Item> </Order> </Orders> But the XML I want it to produce would lokk like this: <Orders> <Order> <OrderID>1</Order...

XML file vs Windows Registry
Hi I just have a quick question. One of our Windows based application uses the registry for configuration type options and some other things. I want to modify our application to move to use a XML file instead of the registry. The other engineer argues that it is faster and easier to manipulate the registry than File I/O operations with the XML file. I just wanted ask you guys what are the strengths and weaknesses with using a XML file over the registry? Thanks I generally prefer the XML file. I have an custom config section handler in my asp.net app, derived from Craig Andera's thi...

Yahoo Store Integration XML Tag for Item Comment
Hello, Does anyone know the XML tag to import an Item Cooment from a web order. These are the only tags I have seen. <Item num ="0"> <Id>9002</Id> <Code>9002</Code> <Quantity>1</Quantity> <Unit-Price>12.99</Unit-Price> <Description></Description> <Taxable>NO</Taxable> </Item> Thanks Jamie Item Comment is what I meant to say. Not Cooment. Sorry "Jamie W." wrote: > Hello, > Does anyone know the XML tag to import an Item Cooment from a web order. > These are the only tags I have ...

Serialize CString question
Hi, I want to serialize a CString in the document class. It works fine except that there are 2 strange characters at the beginning of the saved file. How can I get rid of it? Here is the code: void CMsgDoc::Serialize(CArchive& ar) { // CString m_sMsgs; if (ar.IsStoring()) { // TODO: add storing code here ar<<m_sMsgs; } else { // TODO: add loading code here ar>>m_sMsgs; } } Thanks in advance. xg Hello! On Wed, 19 Oct 2005 10:39:09 +0800, xg wrote: > Hi, I want to serialize a CString in the document class. It works fine > except that there are ...

Outlook received time incorrect
Hi, I've set my machine's timezone according to Microsoft's instructions: http://support.microsoft.com/default.aspx/kb/914387 I can send an email to myself at 9:00, and it'll be shown in "sent items" as sent at 9:00. But, my Inbox will display the email as if it was sent at 10:00. When viewing the mail, it specifies that it was sent at 9:00. So my problem is that for some reason, although the mail contains information that it was sent at 9:00, outlook's inbox displays it at 10:00. Note: all my calendar items are displayed correctly, and my calender options dis...

Newby Question #3
I am sure that you will tell me that this is not recommended, but I'm going to ask anyway... I have a single domain controller here that is running Win2k with Dual 2.4G processors and a Gig of memory. This server does not do hardly anything all day. It used as a file server only. It is supporting about 60 users. Can I install E2k3 on this server? What are the impacts? If I install a low end server to act as the front end off my DMZ, can I do OWA securely? OWA will only have to support about 5-6 people (which will most likely not all be at the same time). Thanks for any input. Jef...

Beginner Question Re Excel Format
Hello, Using Excel 2007 and XP. New at this. Have Copied to the PC's Clipboard a page of data from a financial program. How do I setup Excel, before doing a Paste of this data, such that Excel "knows" that I want the data to appear in csv format in Excel ? Or, do I (or must I) just Paste it as an Excel Workbook format, and then do a Save-As in the csv format ? Thanks, Bob Have your tried a simple copy & paste? What happens? Do you know about the Data | Text to Columns feature? Can you get the other program to send data to a text file? Sorry to answer a question wi...

CString question
CString ext = path.Right(3); s.Format(_T("length %d\n[FILE %s]\n"), tmpFile.GetLength (), (LPCTSTR)ext); When this line executes I wind up with a string value of "length 1110\n[FILE (null)]\n" If I reverse the parameter usage, I'll get the correct "[FILE GIF]\nlength 1110\n" Does anyone know why I can't use a string for the second optional parameter of Format? Thanks, Scott Since you haven't received any answer yet, I'll throw in my 2 cents. It's not that you cannot use a string for the second parameter (which you by the way don't n...

XML to DataSet please help with selection
I have a two xml files schema is identical. When I read file into dataset and then bind dataset to the form. These are weather files we are getting from weather service. One file has only local weather so I don't have any problems with that, but other has weather for several different locations. Basically I need to select only weather for location if I know its code. I should have exactly same dataset so I will be able bind it to the same form without recoding. I was trying to use dataview, but dataview works only with one table and doesn't produce dataset. I got it working by ...

interest calculation on variable debt needed
Hi all, hope there's someone out there that has needed to do this I need to run a loan / credit account, the amount of which has the ability to go either up or down due to capital payments or drawdowns therefore it is not an amortised loan, but kind of works as if I am running a credit card..... credit cards don't seem to work out future interest, and loans only allow you to amortise one loan please help am guessing the answer is "you can't do that" then seeing as no response "Stevo" wrote: > Hi all, > > hope there's someone out there th...

Exchange 5.5 to Exchange 2003 migration question
Ok, so I have added my new exchange 2003 server to my organization and moved just about everyone to the new server from our antiquated Exchange 5.5 server. I now want to make the Exchange 2003 server the front end server and relegate the Exchange 5.5 server as a back end one until I am ready to retire it. Is there anything I need to do other than changing where the firewall points from the public IP address in order to accomplish this? I think you are using frontend / backend in the wrong context. Check what these things really do, and then rethink what you are trying to accomplish....

Hi Guys. First Time Poster
Hi guys. First time poster long time reader. Just wanted to say "Hi" ;) On a side note my Hubby is REAL excited about this new IPO stock GRDX. They just started trading this one like 2 days ago. It's already almost doubled in just 2 days! My Husband is really excited about this stock. Say's it could make us some really BIG money. You guys should check it out. Just spreading the wealth ;) Go to http://www.otcbb.com and check symbol : GRDX you will see how big the growth is :) Let me know what you guys think ;) -- noah799 ...

Offline Inventory Question
I have a question about transferring products from offline inventory to main inventory. When a product is selected in offline inventory for transfer back to main inventory, it looks like RMS automatically transfers the entire quantity of that item into main inventory. For example, if we have a quantity of 10 of Item A in offline inventory and we want to transfer Item A to main inventory, RMS forces us to send all 10 back to main inventory. I don't see any way to transfer only some of the offline inventory quantity back to main inventory (for example, to move 5 of Item A from offl...

Macro Question #12
Hello All, Could some please tell me how to write a macro that will past the data from cell 1A into cell C10 if C10 is blank and past the date in C11 if C10 is not blank. Thanks for any help sub XX() if cells(10,3)="" then cells(10,3)=cells(1,1) else cells (11,3)=cells(1,1) end sub >-----Original Message----- >Hello All, > >Could some please tell me how to write a macro that will >past the data from cell 1A into cell C10 if C10 is blank >and past the date in C11 if C10 is not blank. > > >Thanks for any help >. > Thanks for the reply >----...

Time Card Report #2
Does anyone know if there is a more user friendly template for Time Card report ? We pay employees every 2 weeks and whenever I run a 2 week report, it only shows one date and below this date it sums up 2 dates of cumulative time worked instead of showing the isolated 2 dates. In other words, under a Monday 5/1, it will show 15 hours which actually means that the person worked cumulatively 15 hours on Monday 5/1 AND Monday 5/8... but Time Card report doesn't show the 5/8 separately which is quite confusing and invonvenient. Any help would be highly appreciated! Here is an addit...

iniciar xml..
amigos pueden ayudarme donde conseguir lo basico de xml y como empezar a usarlo con ASP y asp.net, solamente se qeu xml funciona como una tabla..pero quisiera saber mas.. gracias.. -- Gerardo Alfredo F. Pa�l Analista de Sistemas gerardo f. paul wrote: > amigos pueden ayudarme donde conseguir lo basico de xml y como empezar a > usarlo con ASP y asp.net, solamente se qeu xml funciona como una tabla..pero > quisiera saber mas.. Start here - "Employing XML in the .NET Framework", http://msdn.microsoft.com/library/en-us/cpguide/html/cpconemployingxmlinnetframework.asp --...

Sorting an XML document.
I have a slightly different sorting question than has been proposed before. My docuement looks like: <Records> <Record> <Sequence>5</Sequence> <Name>E</Name> </Record> <Record> <Sequence>1</Sequence> <Name>A</Name> </Record> <Record> <Sequence>4</Sequence> <Name>D</Name> </Record> <Record> <Sequence>2</Sequence> <Name>B</Name> </Record> <Record> <Sequence>3</Sequence> &...

POS v.2.0 Time Clock display
Is there a file in the File Center that would permit us to implement an aggregate method so our employees can see the total hours worked when they view the Time Clock function? I'm not aware of any way to do this beyond running a report in Manager View, but it's a great suggestion. You should enter this into the suggestion database through CustomerSource. There isn't a selection for POS 2.0, so choose RMS when submitting. https://mbs.microsoft.com/customersource/ "M Kalmus" <MKalmus@discussions.microsoft.com> wrote in message news:25523729-D448-4885-AF...

XML Class and Node InsertAfter
Hi, I’ve made a class to help me accomplish some things faster but I’m having problems inserting nodes. I’ve tried many different ways, but with no success. This is a very stripped down version of what I’m trying to do. I know that I’m simply missing some basic understanding, so hopefully someone can enlighten me. Public Class MYXMLCLASS Public theXMLDocument As New XmlDataDocument Public myXPath As String Sub New() myXPath = "/" Exit Sub End Sub Public Function addDeclaration() As String Dim myDeclaration As XmlDeclaration myDeclaration = theX...