Searching descendant-or-self::*

I am trying to search all descendents of a project named “FINANZEN” with this search:

/FINANZEN/descendant-or-self::*
(reading the excellent tutorial)

This works perfectly well. The focus is on the project “FINANZEN” and all entries are expanded.

Now I’d like to focus on tasks and (sub)projects only, so I’d like to hide notes within the project tree with this search:

(@type = task or @type = project) and (/FINANZEN/descendant-or-self::* )

It seems I cannot combine descendant-or-self::* searches with boolean operators?

Does this seem to work ?

//FINANZEN//not @type=note

(Where //* is a shorthand for the descendant-or-self::* axis)

If FINANZEN is definitely unindented then you can safely write:

/FINANZEN//not @type=note

and if you prefer fully expanded forms, perhaps:

/FINANZEN/descendant-or-self::(not @type=note)

or

/FINANZEN/descendant-or-self::not @type=note

This, incidentally, should also work, I think:

/FINANZEN/descendant-or-self::(@type=project or @type=task)
2 Likes

Wow, excellent! Thank you very much.

So we cannot combine axis searches with boolean searches like I did?

(@type = task or @type = project) and (/FINANZEN/descendant-or-self::* )

1 Like

You can combine the results of two search paths with the set operators:

  • union
  • intersect
  • except

but the place for boolean expressions is in expansions of the * placeholder within a search path.

In the case you give, it would be possible to define two sets:

  • the whole descendant tree of FINANZEN
  • the set of notes

and to subtract one from the other with except, but this approach is slower (computationally more expensive) because it involves three processes in lieu of one:

  • Collecting the first set,
  • collecting the second set,
  • performing a set operation over the two sets to obtain a third set.

On the other hand, it’s possible that you may find it quicker or more intuitive to write a set expression over two searches than a boolean refinement of one search. So an additional route to what you describe might be:

/Finanzen//* except //note
2 Likes