这是我的要求
<test>
<conversationId>495</conversationId>
<conversation>
<origination>DB</origination>
<Content>
<transactions>
<merchantCountry>840</merchantCountry>
<timestamp>2017-06-12T13:49:03.343Z</timestamp>
</test>
我需要timestamp
值
Date=2017-06-12
time=13:49:03
我只需要HH:MM:SS之后不需要任何东西。
预期输出
time=13:49:03
我有一个解决方案,但我正在使用两个变量
<xsl:variable name="time" select="/test/conversation/Content/transactions/timestamp"/>
<xsl:variable name="timechange">
<xsl:value-of select="substring-after($time, 'T')"/>
</xsl:variable>
<xsl:variable name="timechange1">
<xsl:value-of select="substring-before($timechange, '.')"/>
</xsl:variable>
我想知道是否可以在单一陈述中完成同样的事情。
<xsl:value-of select="substring-after(substring-before($time, 'T'), '.')" /> but nothing came.
更新
"timestamp": "2017-07-12T13:49:03.343Z",
"timestamp": "2017-07-12T13:49:03Z",
"timestamp": "2017-07-12T13:49:03.343-00:05",
"timestamp": "2017-07-12T13:49:03.343+00:15",
"timestamp": "2017-07-12T13:49:03+01:05",
"timestamp": "2017-07-12T13:49:03-01:05",
答案 0 :(得分:0)
你的substring-after应该是substring-before,你的substring-before应该是substring-after。
而不是:
<xsl:value-of select="substring-after(substring-before($time, 'T'), '.')" />
尝试:
<xsl:value-of select="substring-before(substring-after($time, 'T'), '.')" />
要处理不包含.
的dateTime,请添加其他concat ...
<xsl:value-of select="substring-before(concat(substring-after($time, 'T'),'.'), '.')" />
或使用substring()
...
<xsl:value-of select="substring($time,12,8)" />
这适用于2017-06-12T13:49:03.343Z
和2017-06-12T13:49:03
。