【问题标题】:xsl format date (substring + concatenate ?)xsl 格式日期(子字符串 + 连接?)
【发布时间】:2010-12-28 16:14:50
【问题描述】:

我有输入

<Date value="20091223"/>

我希望输出是

<Date>23122009</Date>

我试图使用 substring 函数重新格式化日期

<xsl:value-of select="substring($Date,1,4)"/>

但是如何将提取的年份和月份和日期连接在一起。

【问题讨论】:

    标签: c# .net xml xslt


    【解决方案1】:
    <xsl:value-of select="substring(Date/@value, 7, 2)"/>
    <xsl:value-of select="substring(Date/@value, 5, 2)"/>
    <xsl:value-of select="substring(Date/@value, 1, 4)"/>
    

    【讨论】:

      【解决方案2】:

      假设没有保留空白,只需将它们一个接一个地放置:

      <xsl:value-of select="substring($Date,7,2)"/>
      <xsl:value-of select="substring($Date,5,2)"/>
      <xsl:value-of select="substring($Date,1,4)"/>
      

      如果保留空格,只需将它们全部放在一行上,它们之间没有空格。

      Xpath concatenation 函数也可以使用,但我觉得它的可读性较差:

      <xsl:value-of select="concat(substring($Date,7,2), substring($Date,5,2), substring($Date,1,4))"/>
      

      【讨论】:

        【解决方案3】:

        试试这个

        <xsl:value-of select="concat(substring($Date,7,2),substring($Date,5,2),substring($Date,1,4))"/>
        

        【讨论】:

          【解决方案4】:

          看看 XSLT concat function。在你的情况下,它会是这样的(未经测试):

          <xsl:value-of select="concat(substring($Date,1,4), substring($Date,7,2), substring($Date,5,2))"/>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2020-06-01
            • 2014-04-26
            • 2016-12-06
            • 1970-01-01
            • 1970-01-01
            • 2014-05-06
            • 1970-01-01
            相关资源
            最近更新 更多