Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2007, 06:56 AM
Registered User
 
Join Date: Nov 2006
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

 
Old April 3rd, 2007, 07:05 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old April 3rd, 2007, 08:51 AM
Registered User
 
Join Date: Nov 2006
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.






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





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