Why doesn't this XPath query work as I assumed?

Post here questions and problems related to editing and publishing DITA content.
teresarich
Posts: 3
Joined: Wed May 28, 2025 10:38 am

Why doesn't this XPath query work as I assumed?

Post by teresarich »

Hello,
I have the following query (XPath 2.0):

Code: Select all

//xref[contains(@href,'#') and @class='- topic/xref ' and @type!='step' and @type!='fig' and @type!='substep']
I'm looking to find topic and xref elements that have a hash in their href attribute while excluding certain types of elements. The issue is that the query above doesn't show elements with @outputclass='expandable'.

I had to run a separate query to identify those elements:

Code: Select all

//xref[contains(@href,'#') and @outputclass='expandable']
Why doesn't the first, longer query display those elements? I also tried using contains(@class, '- topic/xref') instead of @class='- topic/xref', but it didn't make a difference.
Radu
Posts: 9523
Joined: Fri Jul 09, 2004 5:18 pm

Re: Why doesn't this XPath query work as I assumed?

Post by Radu »

Hi,
There is answer by Michael Kay, the person who develops the Saxon XSLT processor here:

https://stackoverflow.com/questions/105 ... xslt-xslif

Code: Select all

not(A = "NA") returns true if A is either absent, or has a value not equal to "NA". By contrast, A != "NA" returns true if A is present and not equal to "NA"
So in our case "@type!='step'" is not true because @type does not exist as an attribute on the element. But this works "not(@type='step')".

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply