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
在XPATH中,使用当前上下文中的数据过滤其他数据_Xpath - Fatal编程技术网

在XPATH中,使用当前上下文中的数据过滤其他数据

在XPATH中,使用当前上下文中的数据过滤其他数据,xpath,Xpath,是否有一种方法可以使用当前上下文中的数据来过滤statsource中其他位置的节点 例如,如果我有以下XML: <root> <group1> <inst> <type>Foo</type> <value>First Foo</value> </inst> <inst>

是否有一种方法可以使用当前上下文中的数据来过滤statsource中其他位置的节点

例如,如果我有以下XML:

<root>
    <group1>
        <inst>
            <type>Foo</type>
            <value>First Foo</value>
        </inst>
        <inst>
            <type>Bar</type>
            <value>The Bar</value>
        </inst>
        <inst>
            <type>Foo</type>
            <value>Second Foo</value>
        </inst>
    </group1>
    <group2>
        <Filter>
            <FilterType>Foo</FilterType>
        </Filter>
        <Filter>
            <FilterType>Bar</FilterType>
        </Filter>
    </group2>
</root>

有什么可以用来在原始上下文中获取FilterType的吗?

这可以在XPath 2.0中轻松完成:

for $type in /*/*/Filter[1]/FilterType
  return 
     count(/*/group1/*[type eq $type])
根据提供的XML文档计算此Xpath表达式时,将返回正确的结果:

2

在XPath 1.0中,如果事先知道
group1/inst
元素的数量,并且$vType代表所讨论的FilterType,则可以构造以下XPath 1.0表达式:

  ($vType = /*/group1/inst[1]/type)
 +
  ($vType = /*/group1/inst[2]/type)
 +
  ($vType = /*/group1/inst[3]/type)
这再次产生:

二,

最后,如果XSLT中需要XPath 1.0表达式,并且“过滤器”是当前节点

然后,以下XPath表达式计算匹配的确切数目:

  count(/*/group1/inst[type = curent()/FilterType])

这可以在XPath 2.0中轻松完成:

for $type in /*/*/Filter[1]/FilterType
  return 
     count(/*/group1/*[type eq $type])
根据提供的XML文档计算此Xpath表达式时,将返回正确的结果:

2

在XPath 1.0中,如果事先知道
group1/inst
元素的数量,并且$vType代表所讨论的FilterType,则可以构造以下XPath 1.0表达式:

  ($vType = /*/group1/inst[1]/type)
 +
  ($vType = /*/group1/inst[2]/type)
 +
  ($vType = /*/group1/inst[3]/type)
这再次产生:

二,

最后,如果XSLT中需要XPath 1.0表达式,并且“过滤器”是当前节点

然后,以下XPath表达式计算匹配的确切数目:

  count(/*/group1/inst[type = curent()/FilterType])

我正在寻找解决同样问题的办法。目前,我正在使用一个变量来路由这个。。。它看起来像下面这样

<xsl:variable name='FilterType'><xsl:value-of select='FilterType'/></xsl:variable>
<xsl:value-of select='count(/root/group1/inst[type = $FilterType])'/>


但是必须有更好的办法。

我正在寻找解决同样问题的办法。目前,我正在使用一个变量来路由这个。。。它看起来像下面这样

<xsl:variable name='FilterType'><xsl:value-of select='FilterType'/></xsl:variable>
<xsl:value-of select='count(/root/group1/inst[type = $FilterType])'/>

但必须有更好的办法