0

I have the following query (XPath 2.0):

//xref[contains(@href,'#') and @class='- topic/xref ' and @type!='step' and @type!='fig' and @type!='substep']

As you can see, I want to find topic/xref elements with a hash in their href attribute. I want to exclude ceratin types of elements. Problem is, the above query does not display elements with @outputclass='expandable'

I had to run a seperate one to identify them:

//xref[contains(@href,'#') and @outputclass='expandable']

Why does the first, longer query, do not display those elements? I also tried contains(@class='- topic/xref ) instead of @class=' - topic/xref ' and it didn't help.

4

2 回答 2

0

Try below XPath:

//xref[@class="- topic/xref " and contains(@href, "#") and not(@type=("fig", "substep", "table") or @outputclass="expandable")]

that will return xref elements with class="- topic/xref " and # in href attribute but doesn't have type attribute with values "fig", "substep", "table" or outputclass attribute with value "expandable"

于 2017-06-16T10:58:53.893 回答
0

You haven't shown your XML source, but I suspect you were expecting to retrieve elements having no @type attribute. However, the condition @type!='XYZ' is true only for an element that has an @type attribute whose value is something other than 'XYZ'. If my guess is correct, you intended not(@type='XYZ').

于 2017-06-16T11:12:53.747 回答