I need to add dynamic timestamp with the attachment file test.dat as (test_currentDateTime.dat)

sample code which I need to modify:

<node name="testEmail" type="emailoutput"
subject="this is a test mail with an attachment"
xsl="&XSLPATH;test.xsl" outputType="text/plain" >
<attachment type="text/plain" name="test.dat"/>
</node>

How can this be done in the attachment tag that is inside the node tag in xml.

Thanks in advance.

Here's an XSLT Stylesheet:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cs="urn:cs"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="cs">

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

  <msxsl:script language="C#" implements-prefix="cs">
    <![CDATA[
      public string GetCurrentDateTime(string name)
     {
        string filename = name.Substring(0, name.IndexOf('.'));
        string extension = name.Substring(name.IndexOf('.'));

        return(filename + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + extension);
     }
     ]]>
  </msxsl:script>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="attachment">
    <xsl:variable name="vAttachment" select="."></xsl:variable>
    <xsl:element name="attachment">
      <xsl:attribute name="type">
        <xsl:value-of select="$vAttachment/@type"/>
      </xsl:attribute>
      <xsl:attribute name="name">
        <xsl:value-of select="cs:GetCurrentDateTime($vAttachment/@name)"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>

That when run on:

<node name="testEmail" type="emailoutput" subject="this is a test mail with an attachment" xsl="--" outputType="text/plain" >
  <attachment type="text/plain" name="test.dat"/>
</node>

Produces:

<node name="testEmail" type="emailoutput" subject="this is a test mail with an attachment" xsl="--" outputType="text/plain">
  <attachment type="text/plain" name="test_23052012120054.dat" />
</node>

DateTime of run: 23/05/2012 at 12:00:54pm

Hope this helps!

Thanks a lot...It worked :)

Glad it did, dont forget to make the thread as solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.