XSL计数问题
这是示例 xml 文件:
<sample s="false">
<assertionResult>
<name>XML Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
<assertionResult>
<name>Error Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
<assertionResult>
<name>Success Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
<assertionResult>
<name>XML Schema Assertion</name>
<failure>false</failure>
<error>true</error>
</assertionResult>
</sample>
原始文件由 示例 节点组成,例如上面的节点。 我需要计算所有具有 s="false" 属性的 sample 节点,除了具有
的节点> 里面。 这是我用于计数的代码:
select="count(/testResults/*[attribute::s='false'])"
问题是我不知道如何排除具有“true”值的子节点的节点。
This is the sample xml file:
<sample s="false">
<assertionResult>
<name>XML Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
<assertionResult>
<name>Error Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
<assertionResult>
<name>Success Assertion</name>
<failure>false</failure>
<error>false</error>
</assertionResult>
<assertionResult>
<name>XML Schema Assertion</name>
<failure>false</failure>
<error>true</error>
</assertionResult>
</sample>
The original file consists of sample nodes such as the one above.
I need to count all sample nodes with the s="false" attribute, except those which have an <error>true</error>
inside.
This is the code which I am using for counting:
select="count(/testResults/*[attribute::s='false'])"
The problem is that I don't know how to exclude nodes which have the child with the "true" value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以列出几组方括号来向您的条件添加新子句,即
/testResults/*[@s='false'][not(.//error = 'true')]
You can list several sets of square brackets to add new clauses to your condition i.e.
/testResults/*[@s='false'][not(.//error = 'true')]
select="count(/testResults/*[attribute::s='false' and not(error='false')])"
select="count(/testResults/*[attribute::s='false' and not(error='false')])"