2

I have a header path and there should be current system date along with a string.

<xsl:template name="GetHeaderLine">
<xsl:text>A</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Agency</xsl:text>
<xsl:value-of select="Date"/>

The output should be

A,Agency{CurrrentDate},

How can i fetch current date on xslt...?

Anu Basheer A
  • 21
  • 1
  • 4
  • 1
    Easy with XSLT 2.0, bit more involved in XSLT 1.0. Check out this answer http://stackoverflow.com/questions/1575111/can-an-xslt-insert-the-current-date – Zyga Jul 24 '13 at 11:49

3 Answers3

1

If you are using XPath2, use: current-date()

but instead of this:

<xsl:text>A</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Agency</xsl:text>
<xsl:value-of select="Date"/>

I'd be tempted to use something more akin to:

<xsl:value-of select="concat('A,Agency',current-date())"/>
AndyH
  • 134
  • 2
1

I use

<xsl:variable name="now">
    <xsl:value-of select="document(&apos;http://xobjex.com/service/date.xsl&apos;)/date/utc/@stamp"/>
</xsl:variable>

And then you can use the bits you need. You can add "?offset=" to the url for different time zones.

user2532030
  • 655
  • 1
  • 6
  • 10
0

Guys I got the answer....

    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:cs="urn:cs">
<xsl:output method="xml" indent="yes"/>
<msxsl:script language="C#" implements-prefix="cs">
<![CDATA[
public string datenow()
{
return(System.DateTime.Now.ToString("yyyyMMdd"));
}
]]>
</msxsl:script>
<xsl:template name="GetHeaderLine">
<xsl:text>A</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Agency</xsl:text>
<xsl:text>,</xsl:text>
<xsl:value-of select="cs:datenow()"/>
</xsl:template>
</xsl:stylesheet>

ThanQ so much for your help guys

Cheers

Anu Basheer A
  • 21
  • 1
  • 4