我们在我的办公室使用的程序的转换XML文件是出口用XSLT文件转换成XHTML出口报告。 我重写XSLT更改格式,并从源XML文件添加更多信息。
我想包括文件是在最终报告中创建的日期。 但是,当前的日期/时间不包含原始XML文件中,也没有得到关于如何创建XML文件中的任何控制。 似乎没有要任何日期的功能构建到XSLT将返回当前日期。
没有人有任何想法,我如何能够包括我的XSLT转换过程中的当前日期?
我们在我的办公室使用的程序的转换XML文件是出口用XSLT文件转换成XHTML出口报告。 我重写XSLT更改格式,并从源XML文件添加更多信息。
我想包括文件是在最终报告中创建的日期。 但是,当前的日期/时间不包含原始XML文件中,也没有得到关于如何创建XML文件中的任何控制。 似乎没有要任何日期的功能构建到XSLT将返回当前日期。
没有人有任何想法,我如何能够包括我的XSLT转换过程中的当前日期?
日期功能都可用本机,如:
<xsl:value-of select="current-dateTime()"/>
还有current-date()
和current-time()
使用EXSLT日期和时间扩展包。
date.xsl
到您的XSL文件的位置。 date.xsl
。 例如:
<xsl:stylesheet version="1.0"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date"
...>
<xsl:import href="date.xsl" />
<xsl:template match="//root">
<xsl:value-of select="date:date-time()"/>
</xsl:template>
</xsl:stylesheet>
对于MSXML分析器,试试这个:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="urn:sample" extension-element-prefixes="msxml">
<msxsl:script language="JScript" implements-prefix="my">
function today()
{
return new Date();
}
</msxsl:script>
<xsl:template match="/">
Today = <xsl:value-of select="my:today()"/>
</xsl:template>
</xsl:stylesheet>
还读脚本:使用msxsl XSLT样式表脚本和扩展XSLT使用JScript,C#和Visual Basic .NET
Do you have control over running the transformation? If so, you could pass in the current date to the XSL and use $current-date from inside your XSL. Below is how you declare the incoming parameter, but with knowing how you are running the transformation, I can't tell you how to pass in the value.
<xsl:param name="current-date" />
For example, from the bash script, use:
xsltproc --stringparam current-date `date +%Y-%m-%d` -o output.html path-to.xsl path-to.xml
Then, in the xsl you can use:
<xsl:value-of select="$current-date"/>
...
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:local="urn:local" extension-element-prefixes="msxsl">
<msxsl:script language="CSharp" implements-prefix="local">
public string dateTimeNow()
{
return DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
}
</msxsl:script>
...
<xsl:value-of select="local:dateTimeNow()"/>
迟到的回答,但我的解决方案可以在Eclipse XSLT。 Eclipse使用XSLT 1在写这篇文章的时候。 你可以安装一个XSLT 2引擎像撒克逊。 或者你可以使用下面的XSLT 1解决方案中插入当前日期和时间。
<xsl:value-of select="java:util.Date.new()"/>
这将调用Java的数据类输出日期。 它不会工作,除非你也把下面的“java:”定义你<xsl:stylesheet>
标签。
<xsl:stylesheet [...snip...]
xmlns:java="java"
[...snip...]>
我希望可以帮助别人。 这个简单的答案是很难找到我。
format-date(current-date(), '[M01]/[D01]/[Y0001]') = 09/19/2013
format-time(current-time(), '[H01]:[m01] [z]') = 09:26 GMT+10
format-dateTime(current-dateTime(), '[h1]:[m01] [P] on [MNn] [D].') = 9:26 a.m. on September 19.
参考: 格式化日期和时间使用XSLT 2.0和XPath