How to get current date and time in XSLT 1.0

試著忘記壹切 提交于 2019-12-06 15:49:58

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"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!