问题
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