4

I have the following xpath expressions...

//ns:response[1]/ns:return[1]/legs[1]/startDate[1] (Value 01/01/2011)
//ns:response[1]/ns:return[1]/legs[1]/startTime[1] (Value 12:13)

I need to format and concat these values into something like this

2011-08-25T17:35:00

Is this possible to do using xpath functions? An example would be appreciated.

The date format in the input data is dd/mm/yyyy.

Remotec
  • 10,304
  • 25
  • 105
  • 147

3 Answers3

5

As by @Michael Key suggestion (+1), three substring() and one concat() is all what you need. Check at this XSLT example using the XPath you are searching for (use of variables to make expression readable):

<xsl:template match="/">
    <xsl:variable name="sD" select="'01/01/2011'"/>
    <xsl:variable name="sT" select="'12:13'"/>
    <xsl:value-of select="concat(
        substring($sD,7),'-',
        substring($sD,4,2),'-',
        substring($sD,1,2),'T',
        $sT,':00')"/>
</xsl:template>
Emiliano Poggi
  • 24,390
  • 8
  • 55
  • 67
4

It would help to know whether your 01/01/2011 is d/m/y or m/d/y. Either way, it's just a question of calling substring() three times to extract the parts of the data, and then concat() to build up the result.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

Look at XPath 1.0 functions: concat, substring, substring-before, substring-after.

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125