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 May 23rd, 2008, 01:32 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL DateTime format for Excel

i have an XML file which has a date in this format
<ROWSET>
<ROW>
<name> John </name>
<order_date> 10/1/2008</order_date>
<amount> 122 </amount>
</ROW>
<ROW>
<name> Jack </name>
<order_date> 12/6/2008</order_date><amount> 245 </amount>
</ROW>
</ROWSET>

In xsl when i do this

<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<Workbook>
<Worksheet ss:Name="Biogen_Reverse_Payment_CT">
<Table x:FullColumns="1" x:FullRows="1">
<xsl:for-each select="ROWSET/ROW">
<Row>

<Cell><Data ss:Type="String">
<xsl:value-of select="CURRENCY_CODE"/>
</Data></Cell>

<Cell> <Data ss:Type="DateTime">
<xsl:value-of select="CHECK_DATE"/>
</Data> </Cell>

<Cell><Data ss:Type="Number">
<xsl:value-of select="AMOUNT"/>
</Data></Cell>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>

In the resulting output Excel file from this I cannot open the excel fuile as DateTime format is like this "12/6/2008" but in xsl it wants like this "2007-10-18T00:00:00.000"

How do i fix this so i can open the file in excel.




 
Old May 23rd, 2008, 01:48 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Both your example dates are ambiguous, so I'm not sure when you say "12/6/2008" whether you mean 12th June or 6th December.

Your best bet is to avoid such date formats in your XML, and use the international standard format YYYY-MM-DD. If you can't do that then you will have to convert it "by hand", which you can do fairly easily in XSLT 2.0 using regular expressions, or rather more tediously in XSLT 1.0 using string functions such as substring-before, etc.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 23rd, 2008, 03:17 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do i convert from this format mm/dd/yyyy to this format

"2007-10-18T00:00:00.000" using XSL. can you pls tell me any function or example to do it.

I am getting the XML file from a database. so i can get only in this format mm/dd/yyyy

 
Old May 23rd, 2008, 03:57 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT 1.0 or 2.0?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 23rd, 2008, 04:14 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

XSLT 1.0

 
Old May 23rd, 2008, 04:18 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there any function to convert mm/dd/yyyy or from YYYY-MM-DD HH24:MI:SS to 2007-10-18T00:00:00.000

I appreciate ur help.
Thanks



 
Old May 23rd, 2008, 04:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Extract the components into variables, for example the year part is substring-after(substring-after(., '/'), '/'). Use format-number() to force the month and day to two digits. Then use concat() to reassemble the date in the required format.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 23rd, 2008, 04:38 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you please provide an example code so i can modify it accordingly.

 
Old May 23rd, 2008, 05:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please try to write the code yourself. If you can't make it work, show us your attempts and we'll tell you where you went wrong. It's a tedious problem but not difficult - I'm happy to help people with genuine problems understanding the specs, but I'm not going to sit here doing your work for you.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert DateTime Format dnyanubhamare C# 2005 2 February 25th, 2008 09:06 AM
hi! datetime format question.. xkorakidis JSP Basics 0 January 10th, 2008 06:17 AM
Format datetime deb1980 ASP.NET 2.0 Basics 7 April 17th, 2007 12:35 AM
DateTime format quirks ADMystery ASP.NET 1.0 and 1.1 Professional 5 September 18th, 2006 06:02 AM
converting char to datetime format santoshpayal SQL Language 0 September 11th, 2006 06:13 PM





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