W3C home > Mailing lists > Public > xproc-dev@w3.org > September 2008

Re: p:add/set-attribute and p:label-elements

From: Norman Walsh <ndw@nwalsh.com>
Date: Tue, 30 Sep 2008 12:13:03 -0400
To: XProc Dev <xproc-dev@w3.org>
Message-ID: <m2tzbxr4s0.fsf@nwalsh.com>
James Garriss <james@garriss.org> writes:

> It seems that p:add-attribute and p:set-attribute have overlapping
> functionality with p:label-elements.  Can someone plz differentiate these
> for me?  

p:add-attribute adds a single attribute with a single, fixed value to
a set of matching elements.

p:set-attributes adds a collection of attributes, each with a single, fixed
value to a set of matching elements.

In this regard, p:add-attribute is just a convenience step for those
cases where you want to add a single attribute.

<p:add-attribute match="h:div"
                 attribute-name="class"
                 attribute-value="orig.div"/>

is "syntactic sugar" for

<p:set-attributes match="h:div">
  <p:input port="attributes">
    <p:inline>
      <element-name-doesn't-matter class="org.div"/>
    </p:inline>
  </p:input>
</p:set-attributes>

In either case, if you started with

 <h:div>
   <h:div>
     <p>text</p>
   </h:div>
 </h:div>

you'd get

 <h:div class='org.div'>
   <h:div class='org.div'>
     <p>text</p>
   </h:div>
 </h:div>

If you want to set two or more attributes, then p:set-attributes is easier.

What's different about p:label-elements is that the attribute *value*
can vary on a per-element basis.

<p:label-elements match="h:div"
                  attribute="id"
                  label="concat('ID_', $p:index)"/>

would turn the example above into

 <h:div id="ID_1">
   <h:div id="ID_2">
     <p>text</p>
   </h:div>
 </h:div>

Clear(er)?

                                        Be seeing you,
                                          norm

-- 
Norman Walsh <ndw@nwalsh.com> | The function of the imagination is not
http://nwalsh.com/            | to make strange things settled, so much
                              | as it is to make settled things
                              | strange.--G. K. Chesterton

Received on Tuesday, 30 September 2008 16:13:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 30 September 2008 16:13:51 GMT