在XML元素中显示当前日期 [英] Display current date in XML element

查看:843
本文介绍了在XML元素中显示当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用XSL将一个XML转换成另一个。我的问题是,在一个元素中,我必须显示格式为:YYYYMMDD。

I'm using an XSL to transform one XML into another. My problem is that in one element I have to display the current date with the format:YYYYMMDD.

我试图使用像这样的变量:

I tried using a variable like these:

<xsl:variable name="dateNow" select="current-dateTime()"/>
<xsl:variable name="dateNow2" select="current-date()"/>

然后尝试格式化,但没有成功。

And then tried to format then, but no success.

<FRUEHESTER_LIEFERTERMIN><xsl:value-of select="format-dateTime($dateNow, '[Y0001][M01][D01]')"/></FRUEHESTER_LIEFERTERMIN>


推荐答案

究竟发生了什么意思)。你使用的是什么样的XSLT处理器?

What exactly is happening (what does "no success" mean). What XSLT processor are you using?

这是一个最简单的测试用例(输入XML文档无关紧要)。
$ b

Here is a minimal test case of what you are trying to do (input XML document doesn't matter)

    <?xml version="1.0" encoding="UTF-8"?>
&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"  exclude-result-prefixes="xs fn"&gt;

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:variable name="dateNow" select="current-dateTime()"/>
    <xsl:variable name="dateNow2" select="current-date()"/>

    <xsl:template match="/">
        <FL><xsl:value-of select="format-dateTime($dateNow, '[Y0001][M01][D01]')"/></FL>
    </xsl:template>

</xsl:stylesheet>

这里是它产生的结果 - 如果你试试这个测试用例,你会得到相同的结果吗? / p>

and here is what it produces -- do you get the same if you try this test case?

<?xml version="1.0" encoding="UTF-8"?>
<FL>20120111</FL>

这篇关于在XML元素中显示当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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