stm:basisstm:basis
STM by Example
Home > Books > Tutorials and Training Guides > STM Language > stm:basis

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



Attribute
xpaththe target path into the operand document

The stm:basis operation generates the basis set for the given xpath. In linear algebra the basis is the set of unique values from which all others can be composed. stm:basis computes the unique document for a given xpath.

Sounds complex but it's not so bad and is very useful. Say you want to know the set of unique values of, for example, @type attribute in a document. Use stm:basis with xpath="//@type". It's then easy to transform that result into say an XHTML form select element.

What if you wanted to know the set of unique instructions used in an idoc? Use xpath="/descendant::type/text()". Or the set of unique customers from a list of multiple orders - use something like xpath="/orders/order/customer/name/text()"

With declarative processing of XML it is very useful to be able to examine the fundamental structure of a document without the noise of the data. Using xpath="//*" returns the skeleton document without it's data.

stm:basis works with any xpath location these can be elements, text or attributes or any combination.

Example

Example1: The basis elements

This example creates the basis document from which the source document was a linear combination. Checkout data.xml to see how it is composed of this basis set.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>data.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:basis xpath="//*" />
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 2: The unique attribute values

This example returns the set of all attributes and their unique values. They remain in the context of the document tree structure.

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