home contribute faq download

FunctX XQuery Functions


Updates the content of one or more elements



The functx:replace-element-values function takes a sequence of elements and updates their values with the values specified in $values. It keeps all the original attributes of the elements in tact. This is useful if you would like to perform an operation on a sequence of elements, for example, doubling them or taking a substring, without eliminating the elements themselves. The two argument sequences are positionally related; i.e. the first element in $elements takes on the first value in $values, the second element takes on the second value, etc.

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 elements whose content you wish to replace
$values xs:anyAtomicType* the replacement values
return value element()*

XQuery Function Declaration

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

   for $element at $seq in $elements
   return element { node-name($element)}
             { $element/@*,
               $values[$seq] }
 } ;


let $in-xml :=
   <price num="1">12</price>
   <price num="2">20</price>
   <price num="3">5</price>
XQuery ExampleResults
   for $p in $in-xml/price
   return $p * 2)
<price num="1">24</price>
<price num="2">40</price>
<price num="3">10</price>
for $p in $in-xml/price
return functx:replace-element-values(
<price num="1">12.0</price>
<price num="2">20.0</price>
<price num="3">5.0</price>


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

Recommended Reading: