home contribute faq download

FunctX XSLT Functions

functx:id-from-element

Gets the ID of an XML element

Google
Webxsltfunctions.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?

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:id-from-element" as="xs:string?"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="element" as="element()?"/>

  <xsl:sequence select="
  data(($element/@*[id(.) is ..])[1])
 "/>

</xsl:function>

Examples

<xsl:variable name="book" select="doc('http://www.functx.com/input/book.xml')"/>
XPath 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 XSLT Services

Recommended Reading:

XQuery