fn:id( $arg as xs:string*, [$node as node()] ) as element()*
Returns the sequence of element nodes that have an ID value matching the value of one or more of the IDREF values supplied in $arg.
Parameters | |
---|---|
arg | The IDs of the elements to return. |
node | The target node. |
The function returns a sequence, in document order with duplicates eliminated, containing every element node E that satisfies all the following conditions:
for $s in $arg return fn:tokenize(fn:normalize-space($s), ' ') [. castable as xs:IDREF]
Notes:
If the data model is constructed from an Infoset, an attribute will have the is-id property if the corresponding attribute in the Infoset had an attribute type of ID: typically this means the attribute was declared as an ID in a DTD.
If the data model is constructed from a PSVI, an element or attribute will have the is-id property if its schema-defined type is xs:ID or a type derived by restriction from xs:ID.
No error is raised in respect of a candidate IDREF value that does not match the ID of any element in the document. If no candidate IDREF value matches the ID value of any element, the function returns the empty sequence.
It is not necessary that the supplied argument should have type xs:IDREF or xs:IDREFS, or that it should be derived from a node with the is-idrefs property.
An element may have more than one ID value. This can occur with synthetic data models or with data models constructed from a PSVI where an the element and one of its attributes are both typed as xs:ID.
If the source document is well-formed but not valid, it is possible for two or more elements to have the same ID value. In this situation, the function will select the first such element.
It is also possible in a well-formed but invalid document to have an element or attribute that has the is-id property but whose value does not conform to the lexical rules for the xs:ID type. Such a node will never be selected by this function.
let $x := document{ <html xmlns="http://www.w3.org/1999/xhtml"> <p id="myID">hello</p> </html> } return fn:id("myID", $x) => <p id="myID" xmlns="http://www.w3.org/1999/xhtml">hello</p>
xquery version "1.0-ml"; declare namespace xh="http://www.w3.org/1999/xhtml"; let $x := document { <html xmlns="http://www.w3.org/1999/xhtml"> <p id="myID">hello</p> <p>hello</p> </html> } return $x/xh:html/xh:p[. is fn:id("myID")] => <p id="myID" xmlns="http://www.w3.org/1999/xhtml">hello</p>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.