Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Xslt 检查一个节点有多少子节点_Xslt_Xpath - Fatal编程技术网

Xslt 检查一个节点有多少子节点

Xslt 检查一个节点有多少子节点,xslt,xpath,Xslt,Xpath,我有一个这样的XML文件: <manual> <chapter> <section /> <section /> <section /> </chapter> <chapter> <section> <section /> <section />

我有一个这样的XML文件:

<manual>
    <chapter>
        <section />
        <section />
        <section />
    </chapter>
    <chapter>
        <section>
            <section />
            <section />
            <section />
            <section />
            <section />
            <section />
            <section />
            <section />
            <section />
            <section />
        </section>  
        <section />
        <section />
    </chapter>
</manual>
这不起作用,因为count()的输出是一个整数,而节[]需要一个节点集。
像count(//section/section)这样的东西不起作用,因为这将计算所有的节,而不仅仅是一组同级


有没有办法做到这一点

我认为您需要
//section[count(section)>9]
,比较运算符不属于
count
函数调用,正如您所拥有的那样。

我认为您需要
//section[count(section)>9]
,比较运算符不属于
count
函数调用,您可以使用count(./section)+count(./section/section)查找节的总计数,下面是了解节点位置和节计数的代码

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<xsl:for-each select="/manual/chapter">
<xsl:if test="count(./section) + count(./section/section) > 9">
<xsl:value-of select="position()"/>,<xsl:value-of select="count(./section)      + count(./section/section) "/>
</xsl:if>
</xsl:for-each>
  </xsl:template>

 </xsl:stylesheet>

,
您可以使用count(./section)+count(./section/section)查找节的总计数,下面是了解节点位置和节计数的代码

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<xsl:for-each select="/manual/chapter">
<xsl:if test="count(./section) + count(./section/section) > 9">
<xsl:value-of select="position()"/>,<xsl:value-of select="count(./section)      + count(./section/section) "/>
</xsl:if>
</xsl:for-each>
  </xsl:template>

 </xsl:stylesheet>

,
它给出了的总计数。对于其他应用程序很有用,但我正在寻找“一个有9个以上子节点的节点”。这给出了节点的总数。对于其他应用程序很有用,但我正在寻找“一个有9个子节点以上的节点”。