Get current date
"mikej" <[email protected]>
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <[email protected]> |
Hello,
This is my first post I am new to exslt and xslt in general.
My question is:
How do I get current date during a transform?
I would like to use xsl:call-template so I do not have to worry about the
xslt processor.
What I have done:
Downloaded exslt form the web site and installed it on my web server.
I added the namespace definition to the style sheet.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" extension-element-
prefixes="date">
I added the parameter
<xsl:param name="date-time" select="2005-01-01"/>
I added the template call
<fieldset style="width: 10px;">
<legend class="scss">Test Current Month</legend>
<xsl:call-template name="date:date">
<xsl:with-param name="date-time" select="''"/>
</xsl:call-template>
<input type="text" name="textfield" value="{$date-time}"></input>
</fieldset>
However I can not get it to work the following are my results:
Using <xsl:param name="date-time" select="2005-01-01"/>
the value of {$date-time} = 2003
Using <xsl:param name="date-time" select=""/>
Throws an error Expression expected
Using <xsl:param name="date-time" select="ÂÂ"/>
The value of {$date-time} = nothing it is blank
Using <xsl:param name="date-time" select="2005-01-01"/>
With
<fieldset style="width: 10px;">
<legend class="scss">Test Current Month</legend>
<xsl:call-template name="date:date">
<xsl:with-param name="date-time" select="2008-01-01"/>
</xsl:call-template>
<input type="text" name="textfield" value="{$date-time}"></input>
</fieldset>
The value of {$date-time} = 2003
Using <xsl:param name="date-time" select="2008-01-01"/>
With
<fieldset style="width: 10px;">
<legend class="scss">Test Current Month</legend>
<xsl:call-template name="date:date">
<xsl:with-param name="date-time" select="ÂÂ"/>
</xsl:call-template>
<input type="text" name="textfield" value="{$date-time}"></input>
</fieldset>
The value of {$date-time} = 200
This is the complete style sheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" extension-element-
prefixes="date">
<xsl:import href="exslt/date/functions/date/date.date.template.xsl" />
<xsl:output method="html" indent="yes"/>
<xsl:key name="distinct-year" match="MTDYear" use="."/>
<xsl:key name="distinct-month" match="MTDMonth" use="."/>
<xsl:key name="distinct-rm" match="RegionalManager" use="."/>
<xsl:key name="distinct-od" match="OpsDir" use="."/>
<xsl:param name="date-time" select="2005-01-01"/>
<xsl:template match="/">
<fieldset style="width:10px;">
<legend class="scss">Year:</legend><select size="1" class="scss"
onChange="iSel('MTDYear',this.options[this.selectedIndex].value)">
<xsl:for-each select="//MTDYear[generate-id()=generate-id(key('distinct-
year',.))]">
<option><xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/></option>
</xsl:for-each></select>
</fieldset>
<fieldset style="width:10px;">
<legend class="scss">Month:</legend>
select size="1" class="scss" onChange="iSel('MTDMonth',this.options
[this.selectedIndex].value)">
<option value="*All">*All</option>
<xsl:for-each select="//MTDMonth[generate-id()=generate-id(key('distinct-
month',.))]">
<option>
<xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</fieldset>
<fieldset style="width: 10px;">
<legend class="scss">Regional Manager:</legend>
<select class="scss" size="1" onChange="iSel('RegionalManager',this.options
[this.selectedIndex].value)">
<option value="*All">*All</option>
<xsl:for-each select="//RegionalManager[generate-id()=generate-id(key
('distinct-rm',.))]">
<xsl:sort select="." data-type="text"/>
<option>
<xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</fieldset>
<fieldset style="width: 10px;">
<legend class="scss">Operations Director:</legend>
<select class="scss" size="1" onChange="iSel('OpsDir',this.options
[this.selectedIndex].value)">
<option value="*All">*All</option>
<xsl:for-each select="//OpsDir[generate-id()=generate-id(key('distinct-
od',.))]">
<xsl:sort select="." data-type="text"/>
<option>
<xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</fieldset>
<fieldset style="width: 10px;">
<legend class="scss">Test Current Month</legend>
<xsl:call-template name="date:date">
<xsl:with-param name="date-time" select="''"/>
</xsl:call-template>
<input type="text" name="textfield" value="{$date-time}"></input>
</fieldset>
</xsl:template>
</xsl:stylesheet>
TIA
Mike