问题
I am using xslt 1.0, I am trying to print current date and time to my node. Below is the sample xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:em="http://www.emirates.com/tridion/schemas" xmlns:tcmse="http://www.tridion.com/ContentManager/5.1/TcmScriptAssistant" exclude-result-prefixes="em xlink tcmse tcm">
  <xsl:output method="xml" version="1.0" encoding="UTF-16" indent="yes"/>
  <!-- Common XSLT Templates-->
  <xsl:include href="tcm:228-190524-2048"/>
  <!-- root match-->
  <xsl:template match="root">
    <sitedata>
      <resources>        
        <PublishedDate>
          <xsl:value-of select="$publishedDate"/>
        </PublishedDate>
      </resources>     
    </sitedata>
  </xsl:template>
In above XSLT, in the place of $publishedDate I want system current date and time
please suggest!!
回答1:
XSLT 1.0 does not provide any standard way to get the current date/time. You can call an extension function to do it (depends on your processor), or you can pass it to the stylesheet as the value of a parameter.
回答2:
Here is how to do this with the msxsl.exe command-line utility (for MSXML):
XSLT code (testParams.xsl):
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:param name="vDate" select="xyz"/>
 <xsl:template match="/">
  "<xsl:value-of select="$vDate"/>"
 </xsl:template>
</xsl:stylesheet>
XML document (t.xml) (fake, ignored):
<t/>
Command-line:
msxsl t.xml testParams.xsl -o con vDate='%date%'
Result:
"Sun 10/02/2011"
    来源:https://stackoverflow.com/questions/7626309/how-to-get-current-date-and-time-in-xslt-1-0