使用 XPath 格式化日期 [英] Formatting dates using XPath

查看:51
本文介绍了使用 XPath 格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xpath 表达式...

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

这可以使用 xpath 函数吗?一个例子将不胜感激.

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

输入数据中的日期格式为 dd/mm/yyyy.

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

推荐答案

As by @Michael Key 建议 (+1),三个 substring() 和一个 concat() 就是您所需要的.使用您正在搜索的 XPath 检查此 XSLT 示例(使用变量使表达式可读):

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>

这篇关于使用 XPath 格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆