home contribute faq download

FunctX XQuery Functions

functx:id-from-element

Gets the ID of an XML element

Google
Webxqueryfunctions.com

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 Type

NameTypeDescription
$element element()? the element
return value xs:string?

XQuery Function Declaration

See 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])
 } ;

Examples

let $book :=
doc('http://www.functx.com/input/book.xml')
return
XQuery ExampleResultsExplanation
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 Also

fn:idRetrieves elements by their ID
fn:idrefRetrieves elements that refer to other elements based on ID

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery