home contribute faq download

FunctX XQuery Functions


Removes child elements from an XML node, based on name



The functx:remove-elements function removes child elements from the elements in $elements. The $names argument is a sequence of strings that represent child element names to remove. Prefixes can (and must) be used in the $names values for elements that are prefixed in the input documents (using the same prefix). You can also specify wildcard values "*", "*:" and ":*" in the second argument. See the description for functx:name-test for details.

The function does not remove all descendants, just children; see functx:remove-elements-deep to remove all descendants with the specified names.

Note: this function is intended to change the way elements appear in the results of a query, not to update them in an XML database. To update your XML database, you should use the implementation-specific update functions of your processor.

Arguments and Return Type

$elements element()* the element(s) from which you wish to remove the children
$names xs:string* the names of the child elements to remove
return value element()*

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:remove-elements
  ( $elements as element()* ,
    $names as xs:string* )  as element()* {

   for $element in $elements
   return element
      $element/node()[not(functx:name-test(name(),$names))] }
 } ;


let $in-xml-1 :=
   <c>Mixed <b>content</b></c>
let $in-xml-2 :=
<in-xml xmlns:x="http://x">
   <c>Mixed <x:a>content</x:a></c>
XQuery ExampleResults
  <c>Mixed <b>content</b>
  <c>Mixed <x:a xmlns:x="http://x">content</x:a>

Depends On

functx:name-testWhether a name matches a list of names or name wildcards

See Also

functx:remove-elements-deepRemoves descendant elements from an XML node, based on name
functx:remove-elements-not-contentsRemoves descendant XML elements but keeps their content


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

Recommended Reading: