A real XQuery-beginner question, but I can't seem to get around my issue.
I have an XML database videos.xml, in which actors and movies are stored as nodes (I think?)
The actors all have separate IDs, but they're not stored as attributes but as something else (Is there perhaps some built-in attribute for IDs?). The movies all have one or several actorRef attributes referencing actor-IDs.
What I want to query for now is all the movies that are referencing a certain actor-id. Let's say Keanu Reeves has ID "001", then we'd want to find all movies that are referencing this ID -> e.g. Matrix and The Devil's Advocate. Is there some built-in function for this?
Agreed with the commenters that more is needed, but you seem to be looking for the family of functions,
fn:id(),fn:idref(), and new to version 3.1 of the XPath and XQuery Functions and Operators specification,fn:element-with-id(). Here are some illustrations taken from the spec:The expression
id('ID21256')/name()returns"employee". (Thexml:idattribute has theis-idproperty, so the employee element is selected.).The expression
element-with-id('E21256')/name()also returns"employee". (Assuming theempnrelement is given the typexs:IDas a result of schema validation, the element will have theis-idproperty and is therefore selected.)The expression
idref('ID21256')would return any element or attribute referencing theemployeeelement. (Assuming that the referencing node is given the typexs:IDREForxs:IDREFSas a result of schema validation, the node will have theis-idrefsproperty.)