gpt4 book ai didi

XSLT 空值比较

转载 作者:行者123 更新时间:2023-12-02 06:19:09 24 4
gpt4 key购买 nike

我有一个如下的 xml。

<attributes>
<attribute>
<attributeName>agenda-group</attributeName>
<value>generic</value>
</attribute>
<attribute>
<attributeName>auto-focus</attributeName>
<value>true</value>
</attribute>
<attribute>
<attributeName>no-loop</attributeName>
<value>true</value>
</attribute>
<attribute>
<attributeName>salience</attributeName>
<value>73</value>
</attribute>
</attributes>

当我得到上面的 block 时,我需要复制上面的 block ,因为它在结果 xml 中。如果我得到下面的 block ,但没有值

   <attributes>
<attribute>
<attributeName></attributeName>
<value></value>
</attribute>

</attributes>

or
<attributes/>

我需要在生成的 xml 中省略此 block 。我正在使用 xslt 进行翻译。请提供一些指示以获得所需的输出。

最佳答案

使用 identity template并添加这些模板:

<xsl:template match="attributes[not(attribute/value/text())]" />
<xsl:template match="attribute[not(value/text())]" />

这两个空模板捕获 <attributes><attribute>没有值(value)并且不会为它们产生输出的元素,从而有效地删除它们。

关于XSLT 空值比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6562164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com