stm:append-attrstm:append-attr
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:append-attr

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:



Attribute
xpathrequired the target path into the operand document
selectrequired the a single valued relative path into the enclosed fragment

The stm:append-attr operation is used to append an attribute to an element located by an xpath. The select parameter is required, and is the relative xpath to an attribute in the document fragment enclosed by the stm:append-attr element. If the target attribute already exists an exception is thrown, you must use stm:delete first to remove the original attribute and then append the new one. If the xpath value returns multiple targets the attribute is appended to all.

Note: STM rigourously enforces a one-to-many assignment model. That is, there is a single operation object, in this case the attribute, and one or multiple targets, here this is the element to which the attribute is appended. This ensures that the language is kept as simple and as comprehensible as possible. Unfortunately attribute assignment is the exception case where a many-to-one model may have been more appropriate. Future versions of the language may support many-to-many.

Deprecated stm:append-attr has been deprecated. stm:append now supports attributes and should be used instead.

Example

Example 1: Append an Attribute

This example appends the enclosed /x/y fragment to the first <b> element.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:append-attr select="x/y/@feet" xpath="/a/b[1]/c">
            <x>
              <y feet="hooves" preferredname="dobin" tail="true">zebra</y>
            </x>
          </stm:append-attr>
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 2: Append a param substituted fragment to multiple targets

This is a more elaborate example. Here multiple attributes are appended to the root node of the operand document.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:append-attr select="x/y/@feet" xpath="/">
            <stm:param />
          </stm:append-attr>
          <stm:append-attr select="x/y/@tail" xpath="/">
            <stm:param />
          </stm:append-attr>
          <stm:append-attr select="x/y/@preferredname" xpath="/">
            <stm:param />
          </stm:append-attr>
        </stm:group>
      </operator>
      <param>
        <x>
          <y feet="hooves" preferredname="dobin" tail="true">zebra</y>
        </x>
      </param>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

© 2003-2007, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.