home contribute faq download

FunctX XQuery Functions

functx:namespaces-in-use

A list of namespaces used in element/attribute names in an XML fragment

Google
Webxqueryfunctions.com

Description

The functx:namespaces-in-use function returns a list of all the namespaces used in element and attribute names in the scope of $root. It does not include namespaces that are declared but not used, or ones that are used in names that are the content (as opposed to the names) of elements or attributes.

Arguments and Return Type

NameTypeDescription
$root node()? the root node to start from
return value xs:anyURI*

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for April 2005 - January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:namespaces-in-use 
  ( $root as node()? )  as xs:anyURI* {
       
   distinct-values(
      $root/descendant-or-self::*/(.|@*)/namespace-uri(.))
 } ;
XQuery Syntax for July 2004:
declare namespace functx = "http://www.functx.com"; 
declare function functx:namespaces-in-use 
  ( $root as node()? )  as xs:anyURI* {
       
   distinct-values(
      for $node in $root/descendant-or-self::*/(.|@*)
      return namespace-uri($node))
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function namespaces-in-use 
  ( $root as node()? )  as xs:anyURI* {
       
   fn:distinct-values(
      for $node in $root/descendant-or-self::*/(.|@*)
      return fn:namespace-uri($node))
 }

Examples

let $in-xml :=
<authors xmlns="abc" xmlns:d="def">
   <author xmlns="ghi">
      <fName xmlns:x="xyz" x:attr="123">Kate</fName>
      <lName>Jones</lName>
   </author>
</authors>
return
XQuery ExampleResultsExplanation
functx:namespaces-in-use($in-xml)
(abc, ghi, xyz)
def is not listed because it is not used in any names

See Also

fn:namespace-uri-for-prefixThe namespace associated with a prefix, in the scope of an element
fn:in-scope-prefixesThe prefixes that are in scope for an element
fn:namespace-uriThe namespace URI of a node

History

Published OnLast UpdatedContributor(s)
2006-06-272007-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