XSL:计数无法正常工作 - 我的XPath问题? [英] XSL:Number count not working as expected -- Issue with my XPath?

查看:239
本文介绍了XSL:计数无法正常工作 - 我的XPath问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是XML

 < row& 
< cell> blah blah< / cell>

< check>
< option />
< option />
< option />
< option />
< option />
< option />
< / check>
< / row>

以下是XSL

 < xsl:template match =row> 
< xsl:variable name =inputLevel>
< xsl:number count =optionlevel =anyfrom =。/>
< / xsl:variable>

< xsl:value-of select =$ inputLevel/>
< / xsl:template>

我得到的是0。 http://www.w3schools.com/XPath/xpath_syntax.asp 说。表示当前节点。不应该返回6吗?



Edit1:我想在任何级别寻找选项标签,而不仅仅是检查。

如果你想计数后代

如果你想计算后代选项,您不应使用 xsl:number ,但:

 < xsl:variable name =inputLevelselect =count(.// option)> 


Here's the XML

<row>
    <cell>blah blah</cell>

    <check>
        <option/>
        <option/>
        <option/>
        <option/>
        <option/>
        <option/>
    </check>
</row>

Here is the XSL

<xsl:template match="row">
    <xsl:variable name="inputLevel">
        <xsl:number count="option" level="any" from="."/>
    </xsl:variable>

    <xsl:value-of select="$inputLevel"/>
</xsl:template>

All I get is "0". http://www.w3schools.com/XPath/xpath_syntax.asp says "." means the current node. Shouldn't it be returning "6"?

Edit1: I wanted to look for option tags at ANY level, not just check. Should have explained but the option tags could exist at any level below

解决方案

If you want to count descendant options you shouldn't use xsl:number but:

<xsl:variable name="inputLevel" select="count(.//option)"> 

这篇关于XSL:计数无法正常工作 - 我的XPath问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆