SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast bjvad's Avatar
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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
    Thanx!

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be nice to know what your transforming the document with...

    Pass by param

    HTML Code:
      <?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.zip

    Java
    HTML Code:
      <?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...

  3. #3
    SitePoint Enthusiast bjvad's Avatar
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Msxml

    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 . 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"
    xmlnssl="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!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •