开发者

How to convert default mysql modtimes into UTC date time using xslt

I need to convert default mysql modtimes into UTC formated datetimes using xslt.

I have an xml document that contains dates that originated as mysql modtimes in the format: 2010-06-30 15:20:43.0

They are now in an xml document within an element "datestamp" 2010-03-16 13:52:56.0

In order to be published via an oai-pmh feed they need to be converted to UTC format: 2010-06-30T15:20:43Z

ISO 8601 U开发者_运维技巧TC dates are defined here: http://www.w3.org/TR/NOTE-datetime

I don't have access to the original mysql database, only an xml dump.


This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

 <xsl:template match="text()">
  <xsl:value-of select=
   "concat(
           translate(substring-before(.,'.'),
                     ' ',
                     'T'
                     ),
            'Z'
            )
   "/>
 </xsl:template>
</xsl:stylesheet>

when applied on this XML document:

<oai:datestamp xmlns:oai="some:ns">2010-03-16 13:52:56.0</oai:datestamp>

produces the wanted, correct result:

<oai:datestamp xmlns:oai="some:ns">2010-03-16T13:52:56Z</oai:datestamp>

Do note: The value is transformed into the wanted format using a single XPath expression, this is why I added the tag xpath.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜