Description
The functx:id-from-element function takes the $element element and returns its attribute (there can only be one) that is of type xs:ID . If no such attribute exists, or if the argument is the empty sequence, the function returns the empty sequence. The attribute must have been declared to be of type xs:ID in a schema, and validated by that schema, for this function to return it.
Arguments and Return TypeName | Type | Description |
$element |
element()? |
the element |
return value |
xs:string? |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:id-from-element
( $element as element()? ) as xs:string? {
data(($element/@*[id(.) is ..])[1])
} ; |
Exampleslet $book := | doc('https://www.datypic.com/functx./input/book.xml') | return |
XQuery Example | Results | Explanation |
---|
functx:id-from-element($book/book/section[1]) |
preface |
Assumes that the attribute id of $element is declared to be of type xs:ID . |
See Alsofn:id | Retrieves elements by their ID | fn:idref | Retrieves elements that refer to other elements based on ID |
History |
Recommended Reading:
|