home contribute faq download

FunctX XQuery Functions

functx:id-untyped

Gets XML element(s) that have an attribute with a particular value

Google
Webxqueryfunctions.com

Description

The functx:id-untyped function simulates the built-in fn:id function except that the value specified can be the value of any attribute, not just one declared to be of type xs:ID. This is useful for getting elements based on ID when a schema is not present. It returns all elements that have any attribute, regardless of name, whose value is the specified value.

Arguments and Return Type

NameTypeDescription
$node node()* the root node(s) to start from
$id xs:anyAtomicType the "id" to find
return value element()*

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:id-untyped 
  ( $node as node()* ,
    $id as xs:anyAtomicType )  as element()* {
       
  $node//*[@* = $id]
 } ;
XQuery Syntax for July 2004 - November 2005 (CR):
declare namespace functx = "http://www.functx.com"; 
declare function functx:id-untyped 
  ( $node as node()* ,
    $id as xdt:anyAtomicType )  as element()* {
       
  $node//*[@* = $id]
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function id-untyped 
  ( $node as node()* ,
    $id as xdt:anyAtomicType )  as element()* {
       
  $node//*[@* = $id]
 }

Examples

let $in-xml :=
<in-xml>
  <a id="A001">abc</a>
  <b foo="A001">def</b>
  <c id="B001">ghi</c>
</in-xml>
  
return
XQuery ExampleResults
functx:id-untyped($in-xml,'B001')
<c id="B001">ghi</c>
functx:id-untyped($in-xml,'A001')
<a id="A001">abc</a>
<b foo="A001">def</b>
functx:id-untyped($in-xml,'C001')
()

See Also

fn:idRetrieves elements by their ID
fn:idrefRetrieves elements that refer to other elements based on ID
functx:id-from-elementGets the ID of an XML element

History

Published OnLast UpdatedContributor(s)
2006-07-092007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley