xsl-list
[Top] [All Lists]

Re: Actual Date

2003-05-30 04:15:48
On Wed, May 28, 2003 at 01:58:39PM +0200,
 Molnár Ágnes <agi(_at_)harpia(_dot_)homeip(_dot_)net> wrote 
 a message of 205 lines which said:

Can I insert to a HTML code the actual date (ex. 28-05-2003) from
XSL?

Combining replies you already received (params , portable but
inconvenient, and exslt, the best way but not portable), here is what
I do:

  <xsl:param name="current_date">(UNSPECIFIED)</xsl:param>

  <xsl:template match="/">
...
    <xsl:choose>
      <xsl:when test="function-available('date:date-time')">
        <!-- EXSLT available -->        
        <xsl:variable name="now" select="date:date-time()"/>
        <xsl:value-of select="date:year($now)"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="date:month-in-year($now)"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="date:day-in-month($now)"/>
        <xsl:text> (date obtained by the XSL processor)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$current_date"/>
        <xsl:text> (date obtained from the calling program)</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
...

Passing the param depends on the XSLT processor. Here is a part of a
Makefile for xsltproc:

xsltproc -o $@ \
                --stringparam current_date "`date +%Y/%m/%d`" \
                ...
                ${STYLESHEET} $<

And for Sablotron :

sabcmd ${STYLESHEET} $< $@ "\$$current_date=`date +%Y/%m/%d`" 



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



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