在XSLT中使用format-date()方法时出现编译错误 [英] Getting compile error while using format-date() method in XSLT
问题描述
我正在尝试使用XSLT 2.0版将XML转换为CSV。但是在XSLT中使用format-date方法时出现编译错误。
以下是错误:
I am trying to convert a XML to CSV using XSLT with version 2.0. But I get a compile error while using format-date method in XSLT. Following is the error:
对表达式'funcall(format-date,[variable-ref(dt / string),literal-expr([D01] / [M01] / [Y0001])])'。
致命错误:无法编译样式表。
Error checking type of the expression 'funcall(format-date, [variable-ref(dt/string), literal-expr([D01]/[M01]/[Y0001])])'.
FATAL ERROR: 'Could not compile stylesheet'.
XSLT代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date" date:doc="http://www.exslt.org/date">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="dt" select="'2013-04-04'"/>
<xsl:value-of select="format-date($dt, '[D01]/[M01]/[Y0001]')" />
<xsl:value-of select="format-date(current-date(), '[D01]/[M01]/[Y0001]')" />
</xsl:template>
</xsl:stylesheet>
推荐答案
您的变量$ dt是字符串,而不是日期。您需要先使用xs:date('2013-04-04')将其转换为日期,然后才能设置其格式。
Your variable $dt is a string, not a date. You need to convert it to a date using xs:date('2013-04-04') before you can format it.
这篇关于在XSLT中使用format-date()方法时出现编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!