开发者

How to get current date and time in XSLT 1.0

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>
  &l开发者_如何学Got;/xsl:template>

In above XSLT, in the place of $publishedDate I want system current date and time

please suggest!!


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.


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜