SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  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 current date and time to an xml using xsl

    Hi,

    I'm using a DOM parser in VB (MSXML) to convert one xml to another xml using an xsl. I need to add a date tag containing the current date and time in the output xml like :

    <DateTimeStamp>2004-12-29 02:54:55</DateTimeStamp>

    (the date format is yyyy-mm-dd hh:mm:ss)

    I tried many ways including inserting a Java function, but nothing seems to be working

    Plz help!

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    There's no easy way to do this. The easiest thing I can think of would be to create a dynamic webpage with ASP (or similar) that generates XML containing the date. Something like this:
    Code:
    <%
    Response.ContentType = "text/xml"
    
    'function to create ISO date format
    'found at http://www.edoceo.com/creo/vbscript-iso-date.php
    Function iso_date(ByVal dt)
    Dim y: y = Year(dt)
    Dim mo: mo=Month(dt)
    Dim d: d=Day(dt)
    Dim h: h=Hour(dt)
    Dim m: m=Minute(dt)
    Dim s: s=Second(dt)
    
      If mo < 10 Then mo="0" & mo
      If d < 10 Then d="0" & d
      If h < 10 Then h="0" & h
      If m < 10 Then m="0" & m
      If s < 10 Then s="0" & s
      
      iso_date = y & "-" & mo & "-" & d & " " & h & ":" & m & ":" & s
    End Function
    
    Response.Write("<?xml version=""1.0"" encoding=""utf-8""?>")
    Response.Write("<date>")
    Response.Write(iso_date(Now()))
    Response.Write("</date>")
    %>
    If you put this ASP page up on a server, at http://example.com/dategenerator.asp for example, then you could grab the current date in your XSL like so:
    HTML Code:
    <xsl:variable
     name="date" 
     select="document('http://example.com/dategenerator.asp')/date"/>
    ...
    <DateTimeStamp>
    <xsl:value-of select="$date"/>
    </DateTimeStamp>

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

    asp...

    Hi,

    Thanks for the reply. Actually, I'm just converting the xml using a vb tool. I have no server space or anything like that . If I keep the asp page in the same folder as the input xml, what would the path look like? I tried using localhost, but it didn't seem to work. Is there anyway to use javascript or something like that?
    Thanks

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Hmmm...in this case, the only thing I could think of doing would be to feed your transformed XML to a DOM object for further processing, using VB's date functions to create the date format you need, and adding it to the <DateTimeStamp /> element using the DOM object.


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
  •