【问题标题】:How to exclude elements with zero values -XSLT?如何排除具有零值的元素-XSLT?
【发布时间】:2021-10-23 16:13:31
【问题描述】:

我有 100 多个要为其映射的元素的列表。我想检查每个元素是否包含任何“0”值。如果它包含零值,那么我应该从输出中消除该输入文档中存在的特定元素。 这是我下面的示例 xml:

<xml>
<xmls>
<A>0.00</A>
<B>0</B>
<C>123</C>
</xmls>
</xml>

我将元素的值存储在一个变量中,并在我的 xslt 中为每个元素这样写:

<xsl:if test="string-length($C) > 0">
<Z>123</Z>
</xsl:if>

我也试过了:

<xsl:template match="xmls[not(string()]"/>

很难把这个条件写到每一个元素上,他们还有其他方法可以为整个文档做到这一点吗?

【问题讨论】:

    标签: xml xslt xslt-1.0


    【解决方案1】:

    使用

      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="*[not(*) and . = 0]"/>
    

    如果你想删除所有具有数值0的元素。

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多