【问题标题】:Get the total number of nodes and counting nodes获取节点总数和计数节点
【发布时间】:2010-11-12 10:31:06
【问题描述】:

是否可以获得XML节点的总数?

另外,如何使用 XSLT 执行 for 语句?

【问题讨论】:

    标签: xml xslt count xmlnode


    【解决方案1】:

    如果你想计算 XML 的节点,你可以使用 count(object/node),它会是这样的:

     <xsl:value-of select="count(/root/*)"/>
    

    上面的说明会让你知道你的根节点有多少个子节点

    <xsl:for-each select="/root/element-you-wanna-loop" >
        <!-- Do something with your nodes here -->    
    </xsl:for-each>
    

    希望对你有所帮助。

    【讨论】:

    • 如何获取当前节点号?
    • 如果您在当前节点中,您应该为当前节点替换 /root,您可以使用 count(*)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    相关资源
    最近更新 更多