functx:copy-attributes

Copies attributes from one element to another

Description

The functx:copy-attributes function copies attributes from the element in $copyFrom to the element in $copyTo. It leaves all the original attributes and content of $copyTo, except that if $copyTo already has an attribute with the same name of one of $copyFrom's attributes, its value is updated to match $copyFrom.

Parameters

Description

copyTo:element()

the element to copy attributes to

copyFrom:element()

the element to copy attributes from

Examples

The examples below use this input document:

<xsl:variable name="in-xml" as="item()*">
  <in-xml>
     <a>123</a>>
     <b x="1" y="2">456</b>
     <c x="9">123</c>
     <d z="5">123</d>
  </in-xml>
</xsl:variable>

XPath

Results

functx:copy-attributes($in-xml/a, $in-xml/b)

<a x="1" y="2">123</a>

functx:copy-attributes($in-xml/b, $in-xml/c)

<b x="9" y="2">456</b>

functx:copy-attributes($in-xml/d, $in-xml/c)

<d z="5" x="9">123</d>

In a generator

Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-functx-copy-attributes.

[e] example-functx-copy-attributes
    [e] vars
        [e] in-xml
            [e] select
                [v] copy-of(parse-xml('<in-xml><a>123</a>><b x="1" y="2">456</b><c x="9">123</c><d z="5">123</d></in-xml>')/*)
    [e] start
        [e] match
            [v] /
        [e] body
            [e] write-pattern
                [v] examples
    [e] patterns
        [e] examples
            [v] E01: {{ functx:copy-attributes($in-xml/a, $in-xml/b) }}
            [v] E02: {{ functx:copy-attributes($in-xml/b, $in-xml/c) }}
            [v] E03: {{ functx:copy-attributes($in-xml/d, $in-xml/c) }}

See Also