Вот наиболее общий формат обработки даты-времени .Формат ввода и вывода полностью настраивается и передается как параметры:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:call-template name="convertDateTime">
<xsl:with-param name="pDateTime" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat">
<year offset="0" length="4"/>
<month offset="4" length="2"/>
<day offset="6" length="2"/>
<hour offset="8" length="2"/>
<minutes offset="10" length="2"/>
<seconds offset="12" length="2"/>
<zone offset="15" length="5"/>
</xsl:param>
<xsl:param name="pOutFormat">
<y/>-<mo/>-<d/> <h/>:<m/>:<s/> <z/>
</xsl:param>
<xsl:variable name="vInFormat" select=
"document('')/*/xsl:template[@name='convertDateTime']
/xsl:param[@name='pInFormat']"/>
<xsl:variable name="vOutFormat" select=
"document('')/*/xsl:template[@name='convertDateTime']
/xsl:param[@name='pOutFormat']"/>
<xsl:apply-templates select="$vOutFormat/node()"
mode="_convertDateTime">
<xsl:with-param name="pDateTime" select="$pDateTime"/>
<xsl:with-param name="pInFormat" select="$vInFormat"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="y" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/year/@offset,
$pInFormat/year/@length)"/>
</xsl:template>
<xsl:template match="mo" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/month/@offset,
$pInFormat/month/@length)"/>
</xsl:template>
<xsl:template match="d" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/day/@offset,
$pInFormat/day/@length)"/>
</xsl:template>
<xsl:template match="h" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/hour/@offset,
$pInFormat/hour/@length)"/>
</xsl:template>
<xsl:template match="m" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/minutes/@offset,
$pInFormat/minutes/@length)"/>
</xsl:template>
<xsl:template match="s" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/seconds/@offset,
$pInFormat/seconds/@length)"/>
</xsl:template>
<xsl:template match="z" mode="_convertDateTime">
<xsl:param name="pDateTime"/>
<xsl:param name="pInFormat"/>
<xsl:value-of select=
"substring($pDateTime,
1+$pInFormat/zone/@offset,
$pInFormat/zone/@length)"/>
</xsl:template>
</xsl:stylesheet>
, когда это преобразование применяется к следующему документу XML :
<dateTime>20101115083000 +0200</dateTime>
желаемый, правильный результат выдается :
2010-11-15 08:30:00 +0200