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 September 17th, 2014, 03:27 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I format transformed time in xslt

I want to display my time in 24 hour format. My xml time is 1:10 PM but I want it to display as 13:10:00.
How do I change my xslt to display correct time format? My xslt code is not working.

It is displaying this:
<ext:ProtectionOrderServiceTime>NaN:NaN:NaN-NaN:00</ext:ProtectionOrderServiceTime>

But this is what I want:

<ext:ProtectionOrderServiceTime>13:10:00</ext:ProtectionOrderServiceTime>

Here is my xslt element code
Code:
<ext:ProtectionOrderServiceTime>
<xsl:value-of select="mscef:formatTime(string(@timeServed))"/>
</ext:ProtectionOrderServiceTime>
Here is the xml that is transformed

XML element code
Code:
<NotificationEvent notificationType="ProtectionOrderService" timeServed="1:10 PM"</NotificationEvent>
 
Old September 17th, 2014, 04:06 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You are calling some library or external function mscef:formatTime. Clearly this function doesn't do what you want it to do. You haven't given us any clues where this function comes from or whether you can change it, so we can't really help very much. Also, you tell us that the input is 1.10PM, but we can't help you write code to convert this unless we know all the possible inputs, e.g. how are noon and midnight represented? (Remember that we're not all familiar with the 12 hour clock as used in your country...)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old September 17th, 2014, 05:24 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
You are calling some library or external function mscef:formatTime. Clearly this function doesn't do what you want it to do. You haven't given us any clues where this function comes from or whether you can change it, so we can't really help very much. Also, you tell us that the input is 1.10PM, but we can't help you write code to convert this unless we know all the possible inputs, e.g. how are noon and midnight represented? (Remember that we're not all familiar with the 12 hour clock as used in your country...)
I live in the USA. The time is the system is entered as 12 hour clock. So noon will be 12:00PM. And Midnight will be 12:00AM. The mscef:formatTime is a local function to convert time but it is not working. So I was looking for a different way to take the time e.g 1:30PM and convert it to 13:30:00.
Does this help?
 
Old September 17th, 2014, 05:43 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you want help finding the bug in the existing function, then you're going to have to show us the code.

If you want to replace it with XSLT code then the way you write this will depend greatly on whether you are using XSLT 1.0 or 2.0. Either way, please don't ask us to write the code for you. If you are having trouble writing the code yourself, show us your best attempt and we will try to explain where you went wrong.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old September 18th, 2014, 11:07 AM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Thumbs up

Quote:
Originally Posted by mhkay View Post
If you want help finding the bug in the existing function, then you're going to have to show us the code.

If you want to replace it with XSLT code then the way you write this will depend greatly on whether you are using XSLT 1.0 or 2.0. Either way, please don't ask us to write the code for you. If you are having trouble writing the code yourself, show us your best attempt and we will try to explain where you went wrong.
That is fair what you said. I am using XSLT 2.0. I have however asked locally and someone helped me with this issue. So it is now resolved. Again, thanks for your advice. I will follow it as I continue to learn and post questions here seeking help. I love this forum!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Run an exe from XSLT to obtain a transformed value eranben XSLT 4 September 13th, 2011 06:02 AM
Time format MDM ASP.NET 2.0 Professional 2 July 12th, 2006 10:37 AM
Adding XSLT transformed XML content dynamically jacob ASP.NET 1.x and 2.0 Application Design 2 December 1st, 2005 04:40 PM
Using xs:time to generate time in desired format krayan001 XSLT 0 June 27th, 2005 04:28 PM
Add XSLT transformed XML (html) on an aspx page humour XSLT 2 September 30th, 2004 05:13 AM





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