.. _functx_add-attributes:
=====================
functx:add-attributes
=====================
Adds attributes to XML elements
Description
~~~~~~~~~~~
The functx:add-attributes function takes one or more XML element nodes, along
with a sequence of attribute names and a sequence of attribute values, and
returns a newly constructed element with those attributes added. The attribute
names and values are positionally related, i.e. the first attribute name
corresponds to the first attribute value, the second name to the second value,
etc. It leaves all the original attributes and content of the element. Unlike
the functx:add-or-update-attributes function, if it already has an attribute
with the same name of one of $attrNames, its original value is retained and the
value in $attrValues is ignored.
Each name must be specified as an xs:QName value. QNames can be constructed with
calls to the xs:QName type constructor or the fn:QName function, as shown in the
examples.
.. list-table::
:widths: 40 60
:header-rows: 1
* - **Parameters**
- **Description**
* - elements:element()
- the element(s) to which you wish to add the attribute
* - attrNames:string()
- the name(s) of the attribute(s) to add
* - attrValues:string()
- the value(s) of the attribute(s) to add
Examples
~~~~~~~~
.. list-table::
:widths: 50 50
:header-rows: 1
* - **XPath**
- **Results**
* - functx:add-attributes($in-xml/a, xs:QName('att1'), 1)
- x
* - functx:add-attributes($in-xml/a, (xs:QName('att1'),xs:QName('att2')), (1,2))
- x
* - functx:add-attributes($in-xml/b, (xs:QName('att1'),xs:QName('att2')), (1,2))
- x
* - functx:add-attributes($in-xml/a, xs:QName('new:att1'), 1)
- x
* - functx:add-attributes($in-xml/a, QName('http://new','new:att1'), 1)
- x
See Also
~~~~~~~~
.. toctree::
:titlesonly:
:glob:
* :ref:`functx_add-or-update-attributes`.
* :ref:`functx_update-attributes`.
* :ref:`functx_copy-attributes`.
* :ref:`functx_remove-attributes`.