Use XPath/XQuery to do this. Refer to the examples page for an example on how to do this.
Get whether a node is contained in a document.
Refer to blueprintQuery for more information on how to import and use this function.
Whether the node is contained in a document