Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 否定在条件中更可取吗?_Xml_Xslt_Negation - Fatal编程技术网

Xml 否定在条件中更可取吗?

Xml 否定在条件中更可取吗?,xml,xslt,negation,Xml,Xslt,Negation,我有一些XML文件,其中保存的记录集的某个数量有时等于0。 现在我必须扔掉那些记录集。我做了以下几件事 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="@*|node()"> <xsl:copy>

我有一些XML文件,其中保存的记录集的某个数量有时等于0。 现在我必须扔掉那些记录集。我做了以下几件事

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<!-- delete 0-quantity records -->
<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[productQuantityinttrue='0']"/>

</xsl:stylesheet>

它基本上可以工作:它复制除productQuantityinttrue=0的以外的所有内容。但有时会删除一些不应该删除的记录集。 现在我的问题是,是否最好与这样的谈判一起工作

<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[not(productQuantityinttrue='0')]"


它基本上可以工作:它复制所有的东西,除了那些带有 productQuantityinttrue=0。但有时会删除记录集 那不应该

您没有提供重新处理此问题的示例

我猜您可以使用以下方法解决此问题:

<xsl:template match=
   "Rows/R[not(productQuantityinttrue[2]) 
         and 
           productQuantityinttrue='0'
          ]"/>


match
属性中的表达式只选择只有一个子
productQuantityinttrue
行/R
元素,该子元素的字符串值为
'0'

好问题,+1。请参阅我的答案,以猜测是什么导致了问题(始终提供完整的数据来重新设置问题!)以及解决方案。您好,Dimitre,谢谢您的回答。我现在提供了一个有2个记录集的示例。当然,实际上是50多套。我认为我所走的漫长道路也可能导致问题。在你的问题中,我不理解的是“productQuantityinttrue[2]”。如果每个记录集真的只有一个“productQuantityinttrue”,我需要它吗?@Peter:谢谢你提供了一个例子。然而,本例并没有说明您的陈述“有时会删除不应该删除的记录集”。您需要展示一个发生这种不必要的删除的示例,并且需要解释为什么不应该删除已删除的元素。这是必要的,以便修改空(删除)模板的匹配模式,使其完全匹配并删除所需的元素。只要“productQuantityinttrue”不是“0”,就不应删除它。因此,只需删除0-1。我不能提供一个不必要的删除发生的例子,因为局部(氧气)输出总是正常的。只有在服务器上运行时,才会出现这种情况。我肯定会将路径缩短为“Rows/R…”,就像您在示例中所做的那样,并检查productQuantityinttrue='0',看看是否再次发生这种情况。彼得,再次感谢你的努力
<!-- delete 0-quantity records --> 

<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[productQuantityinttrue='0']"/>
<xsl:template match=
   "Rows/R[not(productQuantityinttrue[2]) 
         and 
           productQuantityinttrue='0'
          ]"/>