Adding a date time stamp to an xml using xsl

hi…
complete newbie to xsl here. i’m writing an xsl stylesheet to convert one xml to another. within this xsl, i need to generate a date time stamp which will insert the current date and time into the output xml in the format yyyy-mm-dd hh:mm:ss. the output xml tag should look something like this:

<DateTimeStamp>2004-10-25 02:54:55</DateTimeStamp>

Any ideas would be really helpful. I’m really in the dark about this one :frowning:
Thanx!

It would be nice to know what your transforming the document with…

Pass by param


  <?xml version="1.0"?>
  <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
    <xsl:variable name="timestamp" value="false" />
  
    <xsl:template mode="datetime" match="*">
  	<datetime>
  	  <xsl:value-of select="$timestamp"/>
  	</datetime>
    </xsl:template>
  </xsl:stylesheet>
  

EXSLT
MS-XML: http://www.exslt.org/date/functions/date-time/date.date-time.zip

Java


  <?xml version="1.0"?>
  <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="java"
    xmlns:java="http://xml.apache.org/xslt/java">
  
    <xsl:template mode="datetime" match="*">
  	<datetime>
 	 <xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('yyyyMMddHHmmss' ), java:java.util.Date.new())"/>
  	</datetime>
    </xsl:template>
  </xsl:stylesheet>
  

There are many more methods, but you really need to indicate what technologies you are using to transform the document…

I’m using MSXML for transformation. Right now I’m just opening my input xml and checking the output using Marrowsoft Xselerator. If possible, I don’t want to use java to generate date-time stamp. I didn’t really understand the first code snippit :confused: . How do you pass by param? I tried inserting this code into my xsl, but i get an error saying “xsl:template may not be used here”. Here’s what I did…

<xsl:stylesheet version=“1.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
<xsl: output method=“xml” omit-xml-declaration=“yes” />
<xsl:template match=“Input”>
<Result>
<xsl:variable name=“timestamp”/>
<xsl:template mode=“datetime” match=“*”>
<datetime>
<xsl:value-of select=“$timestamp”/>
</datetime>
</xsl:template>

                                    ...........

(i took out value=“false” in the<xsl:variable name=“timestamp” value=“false” />
coz that was popping up an error saying “Attribute ‘value’ is invalid on 'xsl:variable”)

   If you could please explain what happened up there or any other suggestions, it would be really helpful!