È possibile convertire stringhe come 30042013
(30 aprile 2013) in un formato di data?Come analizzare la stringa fino alla data in xslt 2.0
modo da poter utilizzare in un secondo momento nelle funzioni come format-date
È possibile convertire stringhe come 30042013
(30 aprile 2013) in un formato di data?Come analizzare la stringa fino alla data in xslt 2.0
modo da poter utilizzare in un secondo momento nelle funzioni come format-date
fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?)
permette di convertire i suoi argomenti a xs:dateTime
.
Basta usare fn:substring()
e fn:concat()
per ritagliare le parti pertinenti e unirle a yyyy-mm-dd
prima di passare a fn:dateTime
.
Come Tomalak detto, è possibile utilizzare substring()
e concat()
per costruire una stringa si può lanciare come un xs:date()
Esempio (Non suona come si desidera una dateTime.):
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="in" select="'30042013'"/>
<xsl:template match="/">
<xsl:variable name="date" select="xs:date(concat(
substring($in,5,4),'-',
substring($in,3,2),'-',
substring($in,1,2)))"/>
<xsl:value-of select="format-date($date,'[MNn] [D], [Y]')"/>
</xsl:template>
</xsl:stylesheet>
produce (con qualsiasi input XML)
April 30, 2013