EXSLT : date:format-date : 解析日期,不解析时间

EXSLT : date:format-date : parsing date, not parsing time

设置: Apache Xalan 2.7.1

输入:

<?xml version="1.0" encoding="UTF-8"?>
<r>
   <generated_date>2015-07-03 11:48</generated_date>
</r>

XSLT :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:xdt="http://exslt.org/dates-and-times"
            exclude-result-prefixes="xdt">
            <xsl:variable name="generated-date" select="xdt:format-date(//generated_date,'YYYY-MM-dd hh:mm:ss')"        />

      <xsl:template match="/">
             <xsl:value-of select="$generated-date"/>
      </xsl:template>
</xsl:stylesheet>

输出:

<generated_date>2015-07-03 12:00:00</generated_date>

Q : Why I can't figure out why time is not being parsed all along with the date. Time should be equal 11:48:00.


Note: Only xslt 1.0 solutions can apply.

I can't figure out why time is not being parsed all along with the date.

AFAICT,它对您不起作用的原因是提供的 date/time 字符串不是函数接受的定义格式之一 - 请参阅:http://exslt.org/date/functions/format-date/index.html

如果要格式化日期和时间,提供的字符串必须格式化为 YYYY-MM-DDThh:mm:ss - 即使用 T 作为日期和时间之间的分隔符,并在时间部分。在这里查看它的工作1http://xsltransform.net/6qVRKwS

Only xslt 1.0 solutions can apply.

我不确定您要在这里寻找什么样的解决方案。提供的字符串已经是所需的格式,除了缺少的秒部分,所以你可以简单地输出:

<xsl:value-of select="concat(given-date,':00')"/>

不需要任何扩展。


(1) 请注意,none 的主要 XSLT 1.0 处理器支持 EXSLT format-date() 函数 - 这包括 Xalan 2.7.1。虽然它似乎可以工作,但正式功能不可用 - 请参阅:http://xsltransform.net/6qVRKwS/1