I'm writing a basic HTML report templating system based on manipulating the data using xPath. Essentially, I need an xPath query which will select a node OR its children if they have a certain class.
$query = $xPath->query (".//*[contains(concat(' ', normalize-space(@class), ' '), ' -delete-if-no-stock ')]", $node);
I understand that the xPath selector .//*[contains(concat(' ', normalize-space(@class), ' '), ' -delete-if-no-stock ')]
is specifically looking at descendant nodes of the $node
parameter.
I would like an xPath query that essentially asks "the node or any of its children". I know that there is a union operator, |
, but I haven't seen how to implement that. I would have imagined something like this: .[contains(concat(' ', normalize-space(@class), ' '), ' -delete-if-no-stock ')] | .//*[contains(concat(' ', normalize-space(@class), ' '), ' -delete-if-no-stock ')]
but this generates an Invalid expression
error.