stm:get-fragmentstm:get-fragment
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:get-fragment

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



Attribute
xpathrequired the target xpath into the operand document

The stm:get-fragment operation extracts a document fragment at an element located by an xpath. The xpath must be unique since the target element becomes the root of the returned document.

Note: get-fragment has dramatic consequences for subsequent processing instructions since the operand document becomes the extracted fragment.

Example

Example 1: Get a Fragment

This example gets the fragment /b/c from the first <b> element at location /a/b[1]

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

Try it

Example 2: Post Get-Fragment Processing

This example first generates new document branch d/e below /a/b[1]/c. As in example 1 we then get the fragment /a/b[1] which now includes the new sub-branch d/e. Note: The final set operation has a reference that starts at the new root /b element.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:create-path newpath="d/e" xpath="/a/b[1]/c" />
          <stm:get-fragment xpath="/a/b[1]" />
          <stm:set select="." xpath="/b/c/d/e"> This was set on the new document </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.