-1

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?

Nyfiken Gul
  • 654
  • 4
  • 20
  • Please provide examples of your XML and what you've already tried. http://stackoverflow.com/help/how-to-ask – wst Sep 29 '16 at 16:21

1 Answers1

0

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:

let $emp :=
    <employee xml:id="ID21256">
        <empnr>E21256</empnr>
        <first>John</first>
        <last>Brown</last>
    </employee>

The expression id('ID21256')/name() returns "employee". (The xml:id attribute has the is-id property, so the employee element is selected.).

The expression element-with-id('E21256')/name() also returns "employee". (Assuming the empnr element is given the type xs:ID as a result of schema validation, the element will have the is-id property and is therefore selected.)

The expression idref('ID21256') would return any element or attribute referencing the employee element. (Assuming that the referencing node is given the type xs:IDREF or xs:IDREFS as a result of schema validation, the node will have the is-idrefs property.)

Joe Wicentowski
  • 5,159
  • 16
  • 26