我正在研究一些XSL,我认为它使用引擎FOP。目前我正在尝试显示从MM / dd / yyyy到长日期(1990年1月1日)的日期格式
XML是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<cf_customer_quotation_expiration_date type="date">2014-11-08</cf_customer_quotation_expiration_date>
</hash>
默认情况下,XSL包含以下代码:(这是我要更改的内容,以便从上面的短日期输出长日期)
<fo:block text-align="right">
<xsl:call-template name="date:format-iso8601-date">
<xsl:with-param name="iso8601-date">
<xsl:value-of select="/hash/cf_customer_quotation_expiration_date" />
</xsl:with-param>
</xsl:call-template>
</fo:block>
如果有人对样式表格式化程序感兴趣:
<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:str="http://exslt.org/strings" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xc="http://www.ecrion.com/2008/xc" xmlns:xf="http://www.ecrion.com/xf/1.0" xmlns:xfd="http://www.ecrion.com/xfd/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" extension-element-prefixes="date str">
<xslt:output indent="yes" encoding="utf-8" />
<xsl:template match="/">
<xslt:template name="date:format-iso8601-date">
<xslt:param name="iso8601-date" />
<xslt:variable name="format">
<xsl:choose>
<xsl:when test="/hash/text/Date_Format != """>
<xsl:value-of select="/hash/text/Date_Format" />
</xsl:when>
<xsl:otherwise>"dd/MM/yyyy"</xsl:otherwise>
</xsl:choose>
</xslt:variable>
<xsl:choose>
<xsl:when test="$format = "yyyy-MM-dd"">
<xsl:value-of select="$iso8601-date" />
</xsl:when>
<xsl:when test="$format = "MM/dd/yyyy"">
<xsl:value-of select="substring($iso8601-date, 6, 2)" />
/
<xsl:value-of select="substring($iso8601-date, 9, 2)" />
/
<xsl:value-of select="substring($iso8601-date, 1, 4)" />
</xsl:when>
<!-- Default to dd/MM/yyyy -->
<xsl:otherwise>
<xsl:value-of select="substring($iso8601-date, 9, 2)" />
/
<xsl:value-of select="substring($iso8601-date, 6, 2)" />
/
<xsl:value-of select="substring($iso8601-date, 1, 4)" />
</xsl:otherwise>
</xsl:choose>
</xslt:template>
</xslt:stylesheet>
答案 0 :(得分:2)
尝试:
<xsl:template name="format-Date">
<xsl:param name="iso8601-date"/>
<xsl:param name="yyyy" select="substring($iso8601-date, 1, 4)"/>
<xsl:param name="mm" select="substring($iso8601-date, 6, 2)"/>
<xsl:param name="dd" select="substring($iso8601-date, 9, 2)"/>
<xsl:param name="mmm" select="substring('JanFebMarAprMayJunJulAugSepOctNovDec', 3 * ($mm - 1) + 1, 3)"/>
<xsl:value-of select="concat($mmm, ' ', number($dd), ', ', $yyyy)"/>
</xsl:template>