I'm using the following xpath to return all "path" elements based on the element "group" value:
//recent/item/location[group="rgrp1"]/path
This works well but the match im looking for isnt always "rgrp1" but it will ALWAYS start with "rgrp". What i would actually like to do is rather than looking for an exact match of "rgrp1", i would rather return all path elements where the group element contains "rgrp". ive tried using contains() but im not having any luck with it. below is a sample of the structure of the file:
<?xml version="1.0" encoding="utf-8"?>
<recent max="16">
<item>
<context>reports</context>
<type>spreadsheet</type>
<subtype>workbook</subtype>
<location>
<group>rgrp1</group>
<hierarchy>h3</hierarchy>
<node>n38</node>
<path>//Reports/Test1</path>
</location>
</item>
<item>
<context>files</context>
<type>frameset</type>
<location>
<group>fgrp6</group>
<hierarchy>h1</hierarchy>
<node>n205</node>
<path>//Reports/Test2</path>
</location>
</item>
</recent>
any help would be greatly appreciated.
I'm using the following xpath to return all "path" elements based on the element "group" value:
//recent/item/location[group="rgrp1"]/path
This works well but the match im looking for isnt always "rgrp1" but it will ALWAYS start with "rgrp". What i would actually like to do is rather than looking for an exact match of "rgrp1", i would rather return all path elements where the group element contains "rgrp". ive tried using contains() but im not having any luck with it. below is a sample of the structure of the file:
<?xml version="1.0" encoding="utf-8"?>
<recent max="16">
<item>
<context>reports</context>
<type>spreadsheet</type>
<subtype>workbook</subtype>
<location>
<group>rgrp1</group>
<hierarchy>h3</hierarchy>
<node>n38</node>
<path>//Reports/Test1</path>
</location>
</item>
<item>
<context>files</context>
<type>frameset</type>
<location>
<group>fgrp6</group>
<hierarchy>h1</hierarchy>
<node>n205</node>
<path>//Reports/Test2</path>
</location>
</item>
</recent>
any help would be greatly appreciated.
This XPath,
/recent/item/location[group[contains(., 'rgrp')]]/path
will select all path
elements with the noted heritage and a sibling group
element whose string value contains a 'rgrp'
substring.
//item[location/group[contains(., 'rgrp')]]/location/path
this ended up working for me
contains()
? – SiKing Commented Jan 9 at 18:32