stm:appendstm:append
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:append

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



Attribute
xpathrequired the target path into the operand document

The stm:append operation is used to append a document fragment or attribute to an element located by an xpath. Document fragments are located below the last child of the target element, attributes are appended to the target element. If the xpath value returns multiple targets the fragment is appended to all.

Example

Example 1: Append a fragment

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 xpath="/a/b[1]">
            <x>
              <y>zebra</y>
            </x>
          </stm:append>
        </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 complex example. It demonstrates a mutlivalued xpath target. The xpath /a/b is ambiguous and produces two <b> elements. The append operation is applied to each of the elements. In addition this uses parameter substitution to obtain the /i/j/k fragment which is appended to <b>.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:append xpath="/a/b">
            <stm:param />
          </stm:append>
        </stm:group>
      </operator>
      <param>param.xml</param>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

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