functx:id-from-element
Gets the ID of an XML element
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.
Parameters |
Description |
|---|---|
element:element() |
the element |
Examples
The examples below use this input document:
<!-- $book -->
<!DOCTYPE book [
<!ELEMENT book (section*) >
<!ELEMENT section ANY >
<!ATTLIST section id ID #REQUIRED >
<!ELEMENT fn ANY >
<!ATTLIST fn fnid ID #REQUIRED >
<!ELEMENT fnref EMPTY >
<!ATTLIST fnref ref IDREF #REQUIRED >
<!ELEMENT secRef EMPTY >
<!ATTLIST secRef refs IDREFS #REQUIRED >
]>
<book>
<section id='preface'>This book introduces XQuery...
The examples are downloadable<fnref ref="fn1"/>...
</section>
<section id='context'>...</section>
<section id='language'>...Expressions, introduced
in <secRef refs='context'/>, are...
</section>
<section id='types'>...As described in
<secRef refs='context language'/>, you can...
</section>
<fn fnid='fn1'>See http://datypic.com.</fn>
</book>
XPath |
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. |
In a generator
Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-functx-id-from-element.
[e] example-functx-id-from-element
[e] vars
[e] book
[e] select
[v] parse-xml('<!DOCTYPE book [ <!ELEMENT book (section*) ><!ELEMENT section ANY ><!ATTLIST section id ID #REQUIRED ><!ELEMENT fn ANY ><!ATTLIST fn fnid ID #REQUIRED ><!ELEMENT fnref EMPTY ><!ATTLIST fnref ref IDREF #REQUIRED ><!ELEMENT secRef EMPTY ><!ATTLIST secRef refs IDREFS #REQUIRED >]><book><section id=''preface''>This book introduces XQuery... The examples are downloadable<fnref ref="fn1"/>... </section><section id=''context''>...</section><section id=''language''>...Expressions, introduced in <secRef refs=''context''/>, are... </section><section id=''types''>...As described in <secRef refs=''context language''/>, you can... </section><fn fnid=''fn1''>See http://datypic.com.</fn></book>')
[e] start
[e] match
[v] /
[e] body
[e] write-pattern
[v] examples
[e] patterns
[e] examples
[v] E01: {{ functx:id-from-element($book/book/section[1]) }}