Use XPath/XQuery to do this. Refer to the examples page for an example on how to do this.
Gets the previous sibling of the given node which matches the given spec
Refer to blueprintQuery for more information on how to import and use this function.
The first sibling matching the spec