stm:replace-for-textstm:replace-for-text
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:replace-for-text

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



Attribute
xpath required the target xpath into the operand document

The stm:replace-for-text operation replaces an element located by an xpath with the text nodes enclosed by the <stm:replace-for-text>. Any children of the target element are destroyed.

Example

Example 1: Replace an element

This example replaces the first <b> element with the fragment /x/y.

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

Try it

Example 2: Replace multiple elements

This example replaces all the <b> elements with the /i/j[1] fragment from the parameter substitution.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:replace xpath="/a/b">
            <stm:param xpath="/i/j[1]" />
          </stm:replace>
        </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.