xsl-list
[Top] [All Lists]

RE: Date problem

2002-12-10 04:05:20
one trick i've used a couple of times for this is to use batch files to
perform the transform, and to use command line parameters to create an xml
file containing the current date.

for example, through dos you'd have a start.txt file:

<?xml version="1.0" encoding="UTF-8"?>
<datetime>
        <time>

and a middle.txt file:

        </time>
        <date>

and a finish.txt file:

        </date>
</datetime>

you'd then have a dos batch file (say, datetime.bat) looking something like
this:

@echo off
type start.txt
time /t
type middle.txt
date /t
type finish.txt

after putting all of these files in the same folder, you'd call this file as
follows:

call datetime.bat > datetime.xml

what you end up with is a file called datetime.xml that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<datetime>
   <time>10:53
        </time>
        <date>Tue 10/12/2002
        </date>
</datetime>

using the document() function you can then import this file in your xsl, and
do whatever you want with the content.  of course, this is only useful if
you're using batch files, as you'd still have to call the batch file before
doing the transform, and if you're doing that then you may as well just pass
in a parameter.  i've found it useful, though, because i can make batch
files that bit more generic using this method, and i can also transform the
content of the datetime.xml file very easily.

i've only tested this on windows 2000, but i expect that it'd work on any
dos version.

b

p.s. if you need to transform this into an xs:datetime format, this might
help:

<!--
create a timestamp variable from the timestamp.xml file
of the form yyyy-mm-ddThh:mm:ss
note that the timestamp.xml file was created at the command
line using batch files and the 'type' command applied to
text files, so the spacing is a little suspect.  to counteract
this, i've used 'normalize-space' to strip leading and trailing
spaces from the file's values before i use them
-->
<xsl:variable name="timestamp">
        <xsl:variable name="date">
                <xsl:value-of
select="substring-after(normalize-space(document('datetime.xml')/datetime/da
te), ' ')"/>
        </xsl:variable>
        <!--
        the batch file produces the date in the format:
        day dd/mm/yyyy
        we need it in the form yyyy-mm-dd, so we separate
        out the components using substrings, and then recombine
        them in the right order
        -->
        <xsl:variable name="day">
                <xsl:value-of select="substring-before($date, '/')"/>
        </xsl:variable>
        <xsl:variable name="month_and_year">
                <xsl:value-of select="substring-after($date, '/')"/>
        </xsl:variable>
        <xsl:variable name="month">
                <xsl:value-of select="substring-before($month_and_year, '/')"/>
        </xsl:variable>
        <xsl:variable name="year">
                <xsl:value-of select="substring-after($month_and_year, '/')"/>
        </xsl:variable>
        <xsl:value-of select="concat($year, '-', $month, '-', $day)"/>
        <!-- we need a 'T' before the time itself -->
        <xsl:text>T</xsl:text>
        <!-- select the time from the document -->
        <xsl:value-of
select="normalize-space(document('datetime.xml')/datetime/time)"/>
        <!--
        add seconds at end to complete the timestamp format
        we now have the xs:dateTime format as required:
        yyyy-mm-ddThh:mm:ss
        -->
        <xsl:text>:00</xsl:text>
</xsl:variable>

|-----Original Message-----
|From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
|[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Hélder Sousa
|Sent: 09 December 2002 15:53
|To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
|Subject: [xsl] Date problem
|
|
|Hi :)
|
|I'm doing a xsl that produces a html code that represent a form
|
|<xsl:element name="form">
|       <xsl:attribute name="action">page</xsl:attribute>
|       <xsl:attribute name="method">post</xsl:attribute>
|       <xsl:attribute name="ID">form1</xsl:attribute>
|       <xsl:element name="input">
|               <xsl:attribute name="type">hidden</xsl:attribute>
|               <xsl:attribute name="name">system</xsl:attribute>
|               <xsl:attribute name="value"><xsl:value-of
|select="@System"/></xsl:attribute>
|       </xsl:element>
|       <xsl:element name="input">
|               <xsl:attribute name="type">hidden</xsl:attribute>
|               <xsl:attribute name="name">todayDate</xsl:attribute>
|               <xsl:attribute name="value">????????</xsl:attribute>
|       </xsl:element>
|</xsl:element>
|
|The question is: how I put the actual date in "????????"? Is there
|any function in xsl that returns the actual date?! Or I have to
|use jscript?!
|
|Tks for the help :)
|
|
|Hélder Sousa
|
|Departamento de Projectos e-business
|I2S Informática - Sistemas e Serviços, S.A.
|Telefone: 22 8340400
|Fax: 22 8340495
|hsousa(_at_)i2s(_dot_)pt
|http://www.i2s.pt
|
|
| XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
|
|
|


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>