stm:deletestm:delete
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:delete

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



Attribute
xpaththe target path into the operand document

The stm:delete operation is used to delete an element, attribute or document fragment located by an xpath.
CAUTION: If the xpath value returns multiple targets all of them are deleted.

Example

Example 1: Delete a branch

This example deletes the complete document branch below and including the first <b> element.

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

Try it

Example 2: Delete multiple targets

This demonstrates a mutlivalued xpath target. The xpath /a/b is ambiguous and produces two <b> elements. The delete operation is applied to each of them!

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

Try it

Example 3: Delete a single leaf element

This example demonstrates deleting a single element. It removes the <c> element from the second <b> element.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:delete xpath="/a/b[2]/c" />
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 4: Delete a set of attributes

This example demonstrates deleting a set of attributes. It removes the food attribute from the all <c> elements.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:delete xpath="/a/b/c/@food" />
        </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.