<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd created_at="2016-12-15T15:02:55Z">
<title created_at="2016-12-15T15:02:55Z">Empire Burlesque</title>
<artist created_at="2016-12-15T15:02:55Z">Bob Dylan</artist>
<cover created_at="2016-12-15T15:02:55Z"/>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
I want to format all occurrences of created_at attribute
input format YYYY-MM-DDTHH:MM:SSZ
output format YYYY-MM-DD HH:MM:SS
I am currently using this following xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Edit dates to conform to dbunit format-->
<xsl:template match="@created_at">
<xsl:copy>
<xsl:call-template name="formatdate">
<xsl:with-param name="datestr" select="@created_at"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="formatdate">
<xsl:param name="datestr" />
<!-- input format YYYY-MM-DDTHH:MM:SSZ -->
<!-- output format YYYY-MM-DD HH:MM:SS -->
<xsl:variable name="datetext">
<xsl:value-of select="substring-before($datestr,'T')" />
</xsl:variable>
<xsl:variable name="timetext">
<xsl:value-of select="substring($datestr,12,18)" />
</xsl:variable>
<xsl:value-of select="concat($datetext, ' ', $timetext)" />
</xsl:template>
</xsl:stylesheet>
However as I debug through the transformation xslt it does not seem to enter the formatdate call-template. Is my xpath wrong? I found articles on modifying the node, but not the attribute. Any help would be much appreciated.
Thank you
Try this