XSLT: Date Format to Long Date



I am working on some XSL for a PDF that I believe uses an engine, FOP. At the moment I am trying to display a date format from MM/dd/yyyy to a long date (Jan 1 , 1990)


The XML is like this:



<?xml version="1.0" encoding="UTF-8"?>
<hash>
<cf_customer_quotation_expiration_date type="date">2014-11-08</cf_customer_quotation_expiration_date>
</hash>


The XSL contains the following code by default:



<fo:block text-align="right">
<xsl:call-template name="date:format-iso8601-date">
<xsl:with-param name="iso8601-date">
<xsl:value-of select="/hash/document_date_iso8601" />
</xsl:with-param>
</xsl:call-template>
</fo:block>


And in case anyone is interested in the stylesheet formatters:



<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet xmlns:xslt="http://ift.tt/tCZ8VR" xmlns:date="http://ift.tt/HkOdXa" xmlns:fo="http://ift.tt/vyPH5E" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:str="http://ift.tt/rkTpc5" xmlns:svg="http://ift.tt/nvqhV5" xmlns:xc="http://ift.tt/13Ro5zj" xmlns:xf="http://ift.tt/10uz9Lr" xmlns:xfd="http://ift.tt/13Ro7aw" xmlns:xsl="http://ift.tt/tCZ8VR" 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 != &quot;&quot;">
<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 = &quot;yyyy-MM-dd&quot;">
<xsl:value-of select="$iso8601-date" />
</xsl:when>
<xsl:when test="$format = &quot;MM/dd/yyyy&quot;">
<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>

No comments:

Post a Comment