XSLT 可以插入当前日期吗? [英] Can an XSLT insert the current date?

查看:26
本文介绍了XSLT 可以插入当前日期吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在办公室使用的一个程序通过将它导出的 XML 文件与 XSLT 文件一起转换为 XHTML 来导出报告.我正在重写 XSLT 以更改格式并从源 XML 文件中添加更多信息.

A program we use in my office exports reports by translating a XML file it exports with an XSLT file into XHTML. I'm rewriting the XSLT to change the formatting and to add more information from the source XML File.

我想在最终报告中包含文件的创建日期.但是当前日期/时间不包含在原始 XML 文件中,我也无法控制如何创建 XML 文件.XSLT 中似乎没有任何日期函数可以返回当前日期.

I'd like to include the date the file was created in the final report. But the current date/time is not included in the original XML file, nor do I have any control on how the XML file is created. There doesn't seem to be any date functions building into XSLT that will return the current date.

有人知道如何在 XSLT 转换期间包含当前日期吗?

Does anyone have any idea how I might be able to include the current date during my XSLT transformation?

推荐答案

XSLT 2

本机提供日期函数,例如:

XSLT 2

Date functions are available natively, such as:

<xsl:value-of  select="current-dateTime()"/>

还有 current-date()current-time().

使用 EXSLT 日期和时间扩展包.

Use the EXSLT date and times extension package.

  1. 日期和时间包github.com/exslt/exslt.github.io/tree/master/date" rel="noreferrer">GitHub.
  2. date.xsl 提取到您的 XSL 文件所在的位置.
  3. 设置样式表标题.
  4. 导入date.xsl.
  1. Download the date and times package from GitHub.
  2. Extract date.xsl to the location of your XSL files.
  3. Set the stylesheet header.
  4. Import 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>

这篇关于XSLT 可以插入当前日期吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆