这是我的 Xml 文档(小片段)。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p> <!-- Current Node -->
<w:r>
<w:pict>
<w:shape>
<w:txbxContent>
<w:p>
<w:r>
<w:t>Table 11: Tanjavur NREGS activities
</w:t>
</w:r>
</w:p>
<w:p/>
</w:txbxContent>
</w:shape>
</w:pict>
</w:r>
<w:r>
<w:t>CHAPTER IV: Findings and analysis
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
现在假设,<w:p>
是我当前正在处理的 Node.Now,在这里我想使用 来测试一个条件。我的条件是,
如果它(当前处理节点)有多个后代 <w:p>
生 child <w:r><w:t>
那么只有我必须在 <w:when>
中执行一些功能.
现在我测试了,
<xsl:choose>
<xsl:when test="descendant::w:p[2]">
<!-- here i have to perform some work -->
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
在我上面的 xml 文档中,当前处理节点有两个后代 <w:p>
。但是,只有一个后代<w:p>
有<w:r><w:t>
children 。又一个后代<w:p>
没有。
但是我的上述 xslt 条件在这种情况下是正确的。如何检查两个后代是否都具有 <w:r><w:t>
children 。
请指导我摆脱这个问题......
最佳答案
使用
<xsl:when test="count(descendant::w:p[w:r/w:t]) > 1">
more than one descendant
<w:p>
that having child<w:r><w:t>
当前节点转换为 XPath 的要求:
- 有一个后代
<w:p>
-->descendant::w:p
- 那个
<w:p>
有一个 child<w:r>
有一个 child<w:t>
-->w:p[w:r/w:t]
- 这样的后代不止一个 -->
count(...) > 1
关于xml - 如何使用 xslt 2.0 检查所有具有当前节点 w:r/w:t 子代的后代::w:p?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8533054/