home contribute faq download

FunctX XSLT Functions

functx:name-test

Whether a name matches a list of names or name wildcards

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

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:name-test" as="xs:boolean"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="testname" as="xs:string?"/>
  <xsl:param name="names" as="xs:string*"/>

  <xsl:sequence select="
$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,':*'))
 "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<pre:a xmlns:pre="ns1">abc</pre:a>
</xsl:variable>
XSLT ExampleResults
<functx:name-test(name($in-xml),('*'>)
<true>rue
<functx:name-test(name($in-xml),('pre:*'>)
<true>rue
<functx:name-test(name($in-xml),('*:a'>)
<true>rue
<functx:name-test(
   name($in-xml),('pre:a','pre:b'>)
<true>rue
<functx:name-test(
   name($in-xml),('a','b','c'>)
<false>alse

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, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery