Xpointer: is it possible to select an empty node-set?

354 views Asked by At

Question

I have an XInclude that includes a node-set resulting from the specified xpointer attribute's expression.

Is it possible to select, with the xpointer, an empty node-set, so to not include anything?


Issue

The reason is that my xincluded & xpointed node could exist and could NOT exist; so I'm getting a:

XInclude error : XPointer evaluation failed

in the case the pointed node does not exist.


Example

The expression is something like:

    xmlns(ns=urn:my:namespace)
    xpointer(/ns:element1/*[ns:elementA | ns:elementB])

I would like to change the XPointer so that the XInclude does NOT include anything (without raising the error) in the case the node is not found.

Something like:

    xmlns(ns=urn:my:namespace)
    xpointer(/ns:element1/*[ns:elementA | ns:elementB | NOT_FOUND_NODES ])

Is there any way to accomplish that?

1

There are 1 answers

0
Emmanuel Tourdot On

Did you try to use xi:fallback instruction ?

For example, if you instruct this

<xi:include href="somedoc.xml" xpointer="xmlns(ns=urn:my:namespace)xpointer(/ns:element1/*[ns:elementA | ns:elementB])" />

and xpointer resource doesn't exists you will get a resource error (as express in xpointer specification). To avoid this, you can use fallback:

<xi:include href="somedoc.xml" xpointer="xmlns(ns=urn:my:namespace)xpointer(/ns:element1/*[ns:elementA | ns:elementB])">
   <xi:fallback><NOT_FOUND_NODES/></xi:fallback>
</xi:include>

so when xpointer will fall in resource error, fallback will insert NOT_FOUND_NODES element