Re: [xsl] Current date in a Xsl variable

Subject: Re: [xsl] Current date in a Xsl variable
From: "M. David Peterson" <conners_dad@xxxxxxx>
Date: Wed, 10 Sep 2003 02:05:19 -0600
actually you can get an xsl variable to store a javascript variable...  many 
will tell you this is not an advisable way to do things and I will back them 
up... this is not the best way to do this.  the best way is to pass the 
variable into the xslt file through various server side technologies.  none 
the less this is how you could do it if you choose to go this route.  Note: 
I have only used this in production using <msxsl:script>.  Im assuming it 
works the same for <xsl:script> but cant guarantee that for sure.

<xsl:script language="javascript" implements-prefix="my">
<![CDATA[


        function returnDate(){

           var d, s;
           d = new Date();
           s += (d.getMonth() + 1) + "/";
           s += d.getDate() + "/";
           s += d.getYear();
           return(s);
        }
]]>
</xsl:script>

<xsl:variable name="date" select="my:returnDate()"/>

then just use $date within your stylesheet to pull the value.  Keep in mind 
that the variable will set itself only once during the transformation of the 
stylesheet.  So, if you try to add a time element and you use the variable 
in a for-each loop you will get the same value everytime.  The way around 
this is to just call the function directly from <xsl:value-of 
select="my:returnDate()"/>.

Anyway, again, there are tons of reasons to avoid using calls to javascript 
functions and only a handful of justifications to ignore the warnings.  Use 
the above at your own risk.

Best regards...

M.David


----- Original Message ----- 
From: <logchem.news@xxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, September 10, 2003 1:34 AM
Subject: [xsl] Current date in a Xsl variable


> Is it possibbe to get the current date in a variable?
>
> I only found JavaScript routines, but it's not possible to store A
> javascript variable in a Xsl variable.
>
> Thanks in advance
> Peter
>
> -- 
> _____________________________________________________________________
> Snel en voordelig ADSL nu voor iedereen bereikbaar.
> Zon Breedband Budget vanaf EUR 14,95 per maand.
> Nu tijdelijk geen aansluitkosten. Bestel snel op zonnet.nl/breedband
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
> 

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


Current Thread