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
在xml中使用xpath中的前一项表示唯一/不同的项_Xml_Xpath - Fatal编程技术网

在xml中使用xpath中的前一项表示唯一/不同的项

在xml中使用xpath中的前一项表示唯一/不同的项,xml,xpath,Xml,Xpath,我想返回唯一项目的列表。在这种情况下,它应该返回 项目1 项目2 我尝试过以下方法: //Item/Group/Name[not(text()=preceding::Item/Group/Name)]/text() //Item/Group/Name[not(text()=preceding::Item/Group/Name/text())]/text() //Item/Group[not(Name/text()=preceding::Item/Group/Name/text())]/Name/

我想返回唯一项目的列表。在这种情况下,它应该返回 项目1 项目2

我尝试过以下方法:

//Item/Group/Name[not(text()=preceding::Item/Group/Name)]/text()
//Item/Group/Name[not(text()=preceding::Item/Group/Name/text())]/text()
//Item/Group[not(Name/text()=preceding::Item/Group/Name/text())]/Name/text()
就是不能让它工作

<List>
    <Item>
        <Group>
            <Name>Item 1</Name>
        </Group>
    </Item>
    <Item>
        <Group>
            <Name>Item 1</Name>
        </Group>
    </Item>
    <Item>
        <Group>
            <Name>Item 2</Name>
        </Group>
    </Item>
</List>

项目1
项目1
项目2

应该做这项工作的:

//List/Item/Group/Name[not(preceding::*/Name/text() = text())]/text()
它将返回所有的“项目”名称,前面没有重复


编辑:我不确定我是否正确理解了您的问题,因为现在我意识到您的解决方案似乎也能工作…

是的,结果是我使用的在线xpath测试工具无法工作。啊!非常感谢。