I'm using xinclude to include some parts of document in another document, for example, in my main document I have:
<document>
<xi:include href="included.xml"
xpointer = "xpointer(*//[@condition="cond1" or not(@condition)])"
xmlns:xi="http://www.w3.org/2001/XInclude" />
</document>
And my included.xml looks like:
<root>
<chapter>
<section condition="cond1">
<para> Condition 1 Para </para>
</section>
<section condition="cond2">
<para> Condition 2 Para </para>
</section>
</chapter>
</root>
My question is, how can I select everything, retaining the proper structure EXCEPT element with attribute condition="cond2" and also none of it's child elements? So I want to select
<root>
<chapter>
<section condition="cond1">
<para> Condition 1 Para </para>
</section>
</chapter>
</root>
The xpointer I have there doesn't work:
xpointer(*//[@condition="cond1" or not(@condition)])
Start by fixing the syntax:
Then look again at the requirements: "EXCEPT element with attribute condition="cond2"
That would be
Now the tricky bit: "and also none of its child elements". In the question title you call them 'subelements' - I will assume that you actually mean descendant elements at any depth.
The literal answer is
But at this point we need to stop. You've tagged this question XPath but it's not actually about XPath at all, it's about XPointer. Specifically it's about an XPointer using the xpointer() scheme, which exists only as a W3C working draft dated 2002 which was never completed. See https://www.w3.org/TR/xptr-xpointer/. So first we need to establish what XPointer implementation you are actually using, and what specification it conforms to.
And then we need to think about what you are trying to achieve in terms of XInclude. I think you are trying to include, not a set of selected elements, but an entire tree with some subtrees removed. When you select a node to include with XInclude, it will bring in that node together with the subtree rooted at that node, whether the child nodes were explicitly selected or not. You can't use XInclude to perform a transformation of the tree that you are including.
So it's not just a syntax problem or an XPath problem. You're basically using the wrong tool for the job.