tags:

views:

51

answers:

5

Hi All,

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

A: 

Doesn't have xslt a substring command?

codymanix
I tried but how to use substring here?
Wondering
The elements in the string have always a fixed position. What exactly is your problem?
codymanix
it is working, but is there any better way of doing that?
Wondering
Define "better". You mean less dependent on the specifics of the format? If so, describe what range of formats you want to handle.
LarsH
I just wanted it to be generic, and not dependent on substring and index.
Wondering
If you're looking at conversions from strings to dates/times generic is almost impossible because time and date formats are so variable. Given the example, substring should work because the positions are going to be consistent, hmm or possibly not - is it 1 Aug or 01 Aug and is it 1:02:03 or 01:02:03 ??
Murph
A: 

This is a good library to use: EXSLT.

dnagirl
A: 

I found this in a discussion - http://geekswithblogs.net/workdog/archive/2007/02/08/105858.aspx which might help you.

shankys
A: 

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)"/>
jasso
A: 

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"&gt;
   <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
DevNull