Getting compile error while using format-date() method in XSLT

限于喜欢 提交于 2019-12-24 12:06:10

问题


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:

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 code:

<?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>

回答1:


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.




回答2:


This worked for me (using Saxon):

<xsl:variable name="dt">2013-04-04</xsl:variable>


来源:https://stackoverflow.com/questions/15812382/getting-compile-error-while-using-format-date-method-in-xslt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!