加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 在XSLT中添加/减去时间

发布时间:2020-12-16 22:56:11 所属栏目:百科 来源:网络整理
导读:我正在使用xpath 2.0. 我想为变量$orario添加30分钟. tempi id="ID_1" orario_part09:20:00/orario_part ... /tempi 这是我的代码,但它不起作用. xsl:template match="tempi" xsl:variable name="orario" select="./orario_part"/ xsl:variable name="totale
我正在使用xpath 2.0.

我想为变量$orario添加30分钟.

<tempi id="ID_1">
    <orario_part>09:20:00</orario_part>
    ...
  </tempi>

这是我的代码,但它不起作用.

<xsl:template match="tempi">
   <xsl:variable name="orario" select="./orario_part"/>
   <xsl:variable name="totale" select="xs:time($orario)+xs:time('00:30:00')"/>
   <time>
       <xsl:value-of select="$totale"/>
   </time>
</xsl:template>

以下是期望的结果:

<time>09:50:00</time>

我怎样才能做到这一点?

解决方法

试试这个:

<?xml version="1.0" encoding="UTF-8"?>
<tempi id="ID_1">
    <orario_part>09:20:00</orario_part>
</tempi>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="2.0" exclude-result-prefixes="#all">
    <xsl:template match="tempi">
        <xsl:variable name="orario" select="./orario_part" />
        <xsl:variable name="totale" select="xs:time($orario)"/>
        <time>
            <xsl:value-of select="$totale +  xs:dayTimeDuration('P0DT0H30M')"/>
        </time>
    </xsl:template>
</xsl:stylesheet>

<time>09:50:00</time>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读