XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

p:add-attribute

<p:declare-step type="p:add-attribute">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/> <!-- XSLTMatchPattern -->
   <p:option name="attribute-name" required="true"/> <!-- QName -->
   <p:option name="attribute-prefix"/> <!-- NCName -->
   <p:option name="attribute-namespace"/> <!-- anyURI -->
   <p:option name="attribute-value" required="true"/> <!-- string -->
</p:declare-step>

The <p:add-attribute> step adds an attribute to an element in a position defined by a XSLT expression. The document to which the attribute is added is indicated at the input port (“source“). The result of the procedure is outputted via the output port (“result“). The attribute is generated by appropriate options of the step. With the help of “match“, the desired location of the attribute is determined by a XSLT expression. “attribute-name“ determines the name of the attribute. Furthermore, a prefix can be indicated by “attribute-prefix“ and a namespace by “attribute-namespace“. In “attribute-value“ the desired content of the attribute is defined. The options “match“, “attribute-name“ and “attribute-value“ are obligatory whereas the other options are optional.

Example

In the following example an attribute is added to the known input document.

<?xml version="1.0" encoding="UTF-8"?>
 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
    <p:input port="source">
       <p:document href="FilmCollection.xml"/>
    </p:input>
    <p:output port="result"/>
    <p:add-attribute attribute-name="Gender" attribute-value="Male" match="/FilmCollection/Film/Author"/>
</p:declare-step>

A "Gender" attribute with the value "Male" would be added to all “Author“ elements in the document after the execution of this stylesheet. Through a combination of <p:with-option> and corresponding loops, the content of the attributes can be processed in a more dynamic way and therefore more sensible. You will find more details about it in the next chapter.