home contribute faq download

FunctX XQuery Functions

functx:name-test

Whether a name matches a list of names or name wildcards

Google
Webdatypic.com

Description

The functx:name-test function tests a name against a list of names or name wildcards. Valid name wildcards are:

*, which matches all names

*:x, where x is a local name, which matches all names with that local name, in any namespace

p:*, where p is a prefix, which matches all names in the namespace associated with that prefix.

Arguments and Return Type

NameTypeDescription
$testname xs:string? the name to test
$names xs:string* the list of names or name wildcards
return value xs:boolean

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:name-test
  ( $testname as xs:string? ,
    $names as xs:string* )  as xs:boolean {

$testname = $names
or
$names = '*'
or
functx:substring-after-if-contains($testname,':') =
   (for $name in $names
   return substring-after($name,'*:'))
or
substring-before($testname,':') =
   (for $name in $names[contains(.,':*')]
   return substring-before($name,':*'))
 } ;

Examples

let $in-xml :=
<pre:a xmlns:pre="ns1">abc</pre:a>
return
XQuery ExampleResults
functx:name-test(name($in-xml),('*'))
true
functx:name-test(name($in-xml),('pre:*'))
true
functx:name-test(name($in-xml),('*:a'))
true
functx:name-test(
   name($in-xml),('pre:a','pre:b'))
true
functx:name-test(
   name($in-xml),('a','b','c'))
false

Depends On

functx:substring-after-if-containsPerforms substring-after, returning the entire string if it does not contain the delimiter

History

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

Recommended Reading:

XQuery