xml 获取节点总数和计数节点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1155580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:38:06  来源:igfitidea点击:

Get the total number of nodes and counting nodes

xmlxsltcountxmlnode

提问by Cesar Hermosillo

Is it possible to get the total number of XML nodes?

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

Also, how does one do a for-statement with XSLT?

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

回答by Cesar Hermosillo

If you want to count the node of you XML you could use count(object/node) and it will be something like this:

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

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

The instruction above will let you know how many child nodes does your root node has

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

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

Hope this helps you.

希望这对你有帮助。