這種轉變:
<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>
當這個XML文檔施加:
<oai:datestamp xmlns:oai="some:ns">2010-03-16 13:52:56.0</oai:datestamp>
產生想要的,正確的結果:
<oai:datestamp xmlns:oai="some:ns">2010-03-16T13:52:56Z</oai:datestamp>
請注意:使用單個XPath表達式將值轉換爲想要的格式,這就是爲什麼我添加了標記xpath
的原因。
好問題(+1)。查看我的答案,瞭解簡單的XSLT(和單線程XPath)解決方案。 :) – 2010-07-18 01:49:55