stm:setstm:set
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:set

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



Attribute
xpaththe target path into the operand document
selectoptional an unambiguous xpath into the child document fragment contained by the stm:set element

The stm:set operation is used to set the value of elements or attributes. It does not create or modify document structure it cannot be used to create or rename elements. The value to be set is obtained from the select xpath location of the enclosed fragment.

Example

Example 1: Set

This example sets /a/b[1]/c, whose initial value is horse, to the value zebra from the /x/y element enclosed by the stm:set operation.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>var:vardoc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:set select="/x/y" xpath="/a/b[1]/c">
            <x>
              <y>zebra</y>
            </x>
          </stm:set>
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 2: Set with value from Param

In this example we introduce param substitution. Any element named <stm:param> within an stm operation element is substituted by the document fragment from the parameter document at the location given by the <stm:param> xpath attribute. As is always the case for any URA the param document is passed to the stm operation by the <param> element of the idoc instruction.

In detail, this example sets the value of /a/[b]/c to the value at /i/j[1]/k that is it sets horse to haddock!

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>vardoc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:set select="/i/j[1]/k" xpath="/a/b[1]/c">
            <stm:param xpath="/*" />
          </stm:set>
        </stm:group>
      </operator>
      <param>varparam.xml</param>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 3: Set an Attribute Value

In this example we set an attribute value.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:set select="/food" xpath="/a/b[1]/c/@food">
            <food>biscuits</food>
          </stm:set>
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

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