开发者

How to extract this date format in xslt [duplicate]

This question already has answers here: How to extract this format in xslt 开发者_StackOverflow中文版 (3 answers) Closed 9 years ago.

I have an xml structure:

 <Date>Mon, 11 Aug 2009 13:15:10 GMT</Date>

i want to extract only 13:15 or '13' and '15'. What is the best way to do that using xslt


This is a simple modification from my answer in your previous question so all the same there mentioned restrictions apply here also.

<xsl:variable name="time" select="substring(Date, string-length(substring-before(Date, ':') - 1, 5)"/>


If you can use XPath 2.0, you could use tokenize():

XML

<?xml version="1.0" encoding="UTF-8"?>
<Date>Mon, 11 Aug 2009 13:15:10 GMT</Date>

XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="text"/>

   <xsl:template match="/Date">
     <xsl:value-of select="tokenize(tokenize(.,' ')[5],':')[position() &lt; 3]"/>
   </xsl:template>

</xsl:stylesheet>

OUTPUT

13 15
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜