XSLT custom date formatting - GSA -
i trying format xslt in dynamic navigation render dates in particular format. code generates following error:
"an unknown error occurred."
xslt code is:
<xsl:template name="customdate-dn"> <xsl:param name="d"/> <xsl:value-of select="format-date($d, '[d01] [mn,*-3] [y0001]', 'en', (), ())"/> </xsl:template> <xsl:template match="pv" mode="display_value"> <xsl:param name="js_escape"/> <xsl:choose> <!-- customizations - fancy date --> <xsl:when test="../@t = 4"> <xsl:call-template name="customdate-dn"> <xsl:with-param name="d" select="@v"/> </xsl:call-template> </xsl:when> <!-- end of customization --> ...
if replace
<xsl:value-of select="format-date($d, '[d01] [mn,*-3] [y0001]', 'en', (), ())"/>
with
<xsl:value-of select="$d"></xsl:value-of>
it seems work, date in wrong format.
i appreciate help. thanks.
update: date looks dd/mm/yyyy
. using xslt 2.0. think problem passing string format-date function. function requires date. not sure how convert dd/mm/yyyy
string date.
a string represents date in format dd/mm/yyyy
not valid xs:date
, cannot used in format-date()
.
but can parse string , convert iso 8601 date, is valid xs:date type. 1 way achieve in xslt 2.0 use <xsl:analyze-string>
extract year, month , day parts regular expression. can rebuild date in iso 8601 format , store result in new variable can pass format-date()
:
<xsl:template name="customdate-dn"> <xsl:param name="d"/> <xsl:variable name="iso-date"> <xsl:analyze-string select="$d" regex="(\d{{1,2}})/(\d{{1,2}})/(\d{{4}})"> <xsl:matching-substring> <xsl:value-of select="regex-group(3)"/> <xsl:text>-</xsl:text> <xsl:value-of select="regex-group(2)"/> <xsl:text>-</xsl:text> <xsl:value-of select="regex-group(1)"/> </xsl:matching-substring> </xsl:analyze-string> </xsl:variable> <xsl:value-of select="format-date($iso-date, '[d01] [mn,*-3] [y0001]', 'en', (), ())"/> </xsl:template>
Comments
Post a Comment