Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 3rd, 2007, 06:56 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default seconds-from-duration

Hi,

I'm fairly new to XSLT and I'm trying to find an example on how to use seconds-from-duration. Basically I have a field in one XML document that looks like this :

<preview_start_time>PT0M15S</preview_start_time>

and when I transform it, I want it to come out looking like this:

<preview>65</preview>

... but finding documentation on using seconds-from-duration that is fit for human use is proving to be utterly impossible. Is there a simple way to use this function?

cheers,
Alex

Reply With Quote
  #2 (permalink)  
Old April 3rd, 2007, 07:05 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Here's an example:

<preview>
  <xsl:value-of select="seconds-from-duration(xs:dayTimeDuration(preview_start_time))"/>
</preview>

With your example that will give you 15 rather than 65. I don't know where you expect 65 to come from. If you want the total number of seconds (1 min 15 secs = 75 secs), you don't want seconds-from-duration (which will give you 15), you want to do

xs:dayTimeDuration(preview_start_time) idiv xs:dayTimeDuration('PT1S')

Remember that you need an XSLT 2.0 processor and that in the above examples you need to declare the xs namespace.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 3rd, 2007, 08:51 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for the helpful response. I'm sure I'll be back once I have a 2.0 processor installed.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
days-from-duration Dinghus XSLT 1 November 21st, 2007 04:05 AM
date duration urgent rjkulkarni2001 ASP.NET 2.0 Professional 0 January 9th, 2006 06:11 AM
duration between dates rjkulkarni2001 Classic ASP Basics 1 January 5th, 2006 07:19 PM
Converting Seconds into Nano seconds and viceversa chandu80 General .NET 0 June 4th, 2005 01:18 AM



All times are GMT -4. The time now is 01:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.