代码之家  ›  专栏  ›  技术社区  ›  justkt

在XSL中处理隐藏在字符串中的整数

  •  0
  • justkt  · 技术社区  · 16 年前

    我有一个存储的时间值,格式如下 H:mm:ss . 小时可以是从0到几天的任意值。这些数据以XML标记的形式发送,并由XSL处理以显示。我想要的显示格式如下:

    D days, HH:mm:ss (hours/minutes)

    考虑到原始的HH,可能超过24,我知道我需要HH/24的下限来获得天数值。原来的HH%24给了我剩余的时间。

    我还使用 xsl:when xsl:if .

    它从小时值中得到了天和小时,这让我很困惑。

    编辑 到目前为止,我正在做以下工作:

    变量声明

    <xsl:variable name="time"><xsl:value-of select="time" /><xsl:variable>
    <xsl:variable name="days"><xsl:value-of select="floor(substring-before(time, ':') / 24)" /></xsl:variable>
    <xsl:variable name="hours"><xsl:value-of select="substring-before(time, ':') mod 24" /></xsl:variable>
    <xsl:variable name="minutes"><xsl:value-of select="substring-after(time, ':')" /></xsl:variable>
    

    <xsl:if test="$days > 0">
        <xsl:value-of select="$days" /> days
    </xsl:if>
    <xsl:value-of select="$hours" />:<xsl:value-of select="$minutes" />
    
    <xsl:choose>
        <xsl:when test="$hours > 0">
            hour<xsl:if test="$hours > 1">s</xsl:if>
        </xsl:when>
        <xsl:otherwise>
           minute<xsl:if test="$minute != '01:00'">s</xsl:if>
        </xsl:otherwise>
     </xsl:choose>
    

    为了澄清,取样时间是 <time>26:15:00</time>

    1 回复  |  直到 16 年前
        1
  •  0
  •   justkt    16 年前

    div 而不是 / . 最重要的是,我需要表达 number

    <xsl:variable name="time"><xsl:value-of select="time" /><xsl:variable>
    <xsl:variable name="totalHours><xsl:value-of select="number(substring-before($time, ':'))" /></xsl:variable>
    <xsl:variable name="days"><xsl:value-of select="floor($totalHours div 24)" /></xsl:variable>
    <xsl:variable name="hours"><xsl:value-of select="$totalHours mod 24" /></xsl:variable>
    <xsl:variable name="minutes"><xsl:value-of select="substring-after(time, ':')" /></xsl:variable>