Connecting Tech Pros Worldwide Help | Site Map

Convert DateTime to seconds

Newbie
 
Join Date: Jan 2009
Location: Denmark
Posts: 13
#1: Feb 27 '09
Hi,

I have some date time in xml file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <ProductionPerformance>
  3.     <ActualStartTime>2008-12-07T01:00:00</ActualStartTime>
  4.     <ActualEndTime>2008-12-09T01:00:00</ActualEndTime>
  5. </ProductionPerformance>
  6.  
where I need to convert ActualStratTime to seconds in xsl:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <xsl:stylesheet version="1.0" 
  4.     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  5.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  6.     xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
  7.  
  8.  
  9. <xsl:include href="date/functions/date-time/date.msxsl.xsl"/>
  10.  
  11. <xsl:template match="/ProductionPerformance">
  12. <item>
  13.     <xsl:variable name="mydatetime" select="'2009-02-27T15:34:01'"/>
  14.     <xsl:value-of select="date:seconds($mydatetime)"/>
  15. </item>
  16. <item>
  17.     <xsl:value-of select="./ActualStartTime"/>
  18. </item>
  19. <item>
  20.     <xsl:variable name="myseconds" select="./ActualStartTime"/>
  21.     <xsl:value-of select="date:seconds($myseconds)"/>
  22. </item>
  23. </xsl:template>
  24. </xsl:stylesheet>
  25.  
I use date:seconds function to convert the ActualStartTime. It works in the first item when I write '2009-02-27T15:34:01'Žas input for the function. However, it does not works anymore when I try to get data from item ./ActualStartTime from the first xml file. I got an error: "Microsoft JScript runtime error Wrong number of arguments or invalid property assignment line = 953, col = 3 (line is offset...
". It seems that it can not get the input.

Could someone help?
Regards
maxin
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: Feb 28 '09

re: Convert DateTime to seconds


Try
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="myseconds">
  2.   <xsl:value-of select="./ActualStartTime"/> 
  3. </xsl:variable>
  4.  
The difference? $myseconds is now a String instead of an XMLNodeList.
Newbie
 
Join Date: Jan 2009
Location: Denmark
Posts: 13
#3: Mar 1 '09

re: Convert DateTime to seconds


Hi,
Thanks for your answer. However, I get the same error as before.
Regards
maxin
Reply