This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: [XSL] Get time and data
- To: XSL List <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] [XSL] Get time and data
- From: Joerg Pietschmann <joerg dot pietschmann at zkb dot ch>
- Date: Fri, 09 Mar 2001 10:09:57 +0100
- Organization: ZKB
- Reply-To: xsl-list at lists dot mulberrytech dot com
KOBILY <KOBILY@terra.es> wrote:
> Hi !!!!
>
> I need to get the data and time but I do not want to use javascript,
> `perl, php, etc.
> Could I get the date and time using xsl ?
>
> Thanks.
There is currently no way to do this from within an XSL sheet.
I use external tools to write the desired information into a
XML file and get the value into the XSL sheet by using document():
Command line frame (requires Unix toolset, Korn shell or bash):
cat >time.xml <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<time>$(date "+%Y-%m-%d %H:%M:%S")</time>
EOF
saxon -o $3 $1 $2
XSL snippet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="time" select="document('time.xml')/time"/>
...
This reads a nicely formatted timestamp into the $time variable.
If you need year, month, day etc. separately, you could structure the
time.xml file:
cat >time.xml <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<time>
<year>$(date "+%Y")</year>
<month>$(date "+%m")</month>
...
</time>
EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="time" select="document('time.xml')/time"/>
...
<my-year><xsl:value-of select="$time/year"/></my-year>
...
Of course, if you work on Windows, creating time.xml may be a
greater challenge. I installed an Unix toolset on my windows
machine (the example above was developed on windows!). There are
several, you might want to check out the free CYGWIN toolkit
at http://www.cygwin.org . Alternatively, you can use WSH, Visual
Basic, Perl or write a java program.
HTH
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list