Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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
Templates 查看子字符串时使用xslt计数_Templates_Xslt_Xpath_Count_Substring - Fatal编程技术网

Templates 查看子字符串时使用xslt计数

Templates 查看子字符串时使用xslt计数,templates,xslt,xpath,count,substring,Templates,Xslt,Xpath,Count,Substring,我想计算符合以下条件的项目数量: /results/errors/error/[@severity='warning'] 及 因此,虽然我的第一个条件可以通过使用内置的count函数轻松计数 计数(//结果/错误/错误[@severity='warning']) 我不知道如何对第二个条件使用count函数,因为它不是Xpath格式 如果您能为我提供任何帮助,我将不胜感激。(我的XML在下面) 理想的答案是:2 谢谢,, 贝琳达 我的xml如下所示: <results version="2

我想计算符合以下条件的项目数量:

/results/errors/error/[@severity='warning']

因此,虽然我的第一个条件可以通过使用内置的count函数轻松计数 计数(//结果/错误/错误[@severity='warning'])

我不知道如何对第二个条件使用count函数,因为它不是Xpath格式

如果您能为我提供任何帮助,我将不胜感激。(我的XML在下面)

理想的答案是:2

谢谢,, 贝琳达

我的xml如下所示:

<results version="2">
    <errors>
        <error id="redundantAssignment" severity="performance" msg="blah, blah.">
            <location file="/farm/user/cow/src/IO/file1.cpp"/>
            <location file="/farm/user/horse//src/IO/file5.cpp"/>
        </error>
        <error id="redundantAssignment" severity="warning" msg="blah, blah.">
            <location file="/farm/user/sheep/src/IO/file1.cpp"/>
            <location file="/farm/user/cow/src/IO/file2.cpp"/>
        </error>
        <error id="redundantAssignment" severity="error" msg="blah, blah.">
            <location file="/farm/user/horse/src/IO/file1.cpp"/>
            <location file="/farm/user/cow//src/IO/file3.cpp"/>
        </error>
        <error id="redundantAssignment" severity="warning" msg="blah, blah.">
            <location file="/farm/user/sheep/src/IO/file1.cpp"/>
            <location file="/farm/user/cow/src/IO/file3.cpp"/>
        </error>
        <error id="redundantAssignment" severity="warning" msg="blah, blah.">
            <location file="/farm/user/sheep/src/IO/file1.cpp"/>
            <location file="/farm/user/horse/src/IO/file3.cpp"/>
        </error>
        <error id="redundantAssignment" severity="style" msg="blah, blah.">
            <location file="/farm/user/sheep/src/IO/file1.cpp"/>
            <location file="/farm/user/horse/src/IO/file4.cpp"/>
        </error>
        <error id="redundantAssignment" severity="style" msg="blah, blah.">
            <location file="/farm/user/sheep/src/IO/file1.cpp"/>
            <location file="/farm/user/horse/src/IO/file2.cpp"/>
        </error>
    </errors>
</results>

通过将第二个测试添加到第一个谓词中,您应该能够将这两个测试组合为一个
计数()

count(/results/errors/error[@severity='warning' and location[not(string-length(substring-before(@file,'cow'))=0)]])
使用示例XML输入,将生成
2

使用Tim C建议的
contains()
进行简化

count(/results/errors/error[@severity='warning' and location[contains(@file,'cow')]])

我相信通过使用contains可以简化现场测试<代码>位置[包含(@file,'cow')]非常感谢您的输入。这对我非常有帮助。我只是不知道如何使用语法。@Belinda-不客气。当然也要看看Tim C的评论。如果此答案足够,请单击其左侧的复选标记接受此答案。谢谢@丹尼尔:谢谢你的邀请。原始解决方案,2。关于如何将复选标记变为绿色的说明(我不熟悉发布问题)。接下来,我如何正式接受TimC提供给我的简洁简化?@Belinda-我将根据Tim的建议编辑我的问题。否则,如果蒂姆把他的建议作为答案,你可以接受他的建议。如果他真的把它作为一个答案,请随意接受他的答案。
count(/results/errors/error[@severity='warning' and location[contains(@file,'cow')]])