home contribute faq download

FunctX XSLT Functions

functx:replace-element-values

Updates the content of one or more elements

Google
Webdatypic.com

Description

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.

Arguments and Return Type

NameTypeDescription
$elements element()* the elements whose content you wish to replace
$values xs:anyAtomicType* the replacement values
return value element()*

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:replace-element-values" as="element()*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="elements" as="element()*"/>
  <xsl:param name="values" as="xs:anyAtomicType*"/>

   <xsl:for-each select="$elements">
     <xsl:variable name="seq" select="position()"/>
     <xsl:element name="{node-name(.)}">
       <xsl:sequence select="@*, $values[$seq]"/>
     </xsl:element>
   </xsl:for-each>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<in-xml>
   <price num="1">12</price>
   <price num="2">20</price>
   <price num="3">5</price>
</in-xml>
</xsl:variable>
XPath ExampleResults
functx:replace-element-values(
   $in-xml/price,
   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(
         $p,concat($p,'.0'))
<price num="1">12.0</price>
<price num="2">20.0</price>
<price num="3">5.0</price>

History

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

Recommended Reading:

XQuery