stm:set-xpath-eval
STM by Example
Release Notes
Developing with NetKernel
Module Development Guide
Introduction
Design Model
Parameter Substitution
Namespaces
Examples readme
Tree Operations
stm:set
stm:append
stm:delete
stm:create-path
stm:get-fragment
stm:rename
stm:apply-ns
stm:remove-ns
stm:insert-before
stm:insert-after
stm:regex
stm:replace
stm:append-text
stm:append-attr
stm:set-xpath-eval
stm:basis
DPML Reference Guide
XRL Reference Guide
XForms Processing Guide
XAccesor/XAHelper
XDA
Session Guide
Mod DB Guide
Compound URI Guide
License
Change History
NetKernel History
Acknowledgements

stm:set-xpath-eval

Set an element or attribute to the result of an xpath expression


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

The stm:set-xpath-eval operation is used to set the value of elements or attributes to a value obtained from an xpath expression. It does not create or modify document structure it cannot be used to create or rename elements. The value to be set is obtained by evaluating an xpath expression located either as the text value of the stm:-set-xpath-eval element or at the xpath location specified by select xpath location of an enclosed fragment. The evaluated xpath expression has the same context as the target xpath, therefore '.' is target node, '..' the parent etc. Both absolute and relative xpaths can be used.

stm:set-xpath-eval is very good at a=a+1 evaluation and assignments since the value of the target node is available in the xpath expression.

Example

Example1: Set attribute value to the size of the elements text string

This example first creates size attributes on all /a/b/c elements. It next sets each of the size attributes to the length of the text contained by the the parents c element. The xpath expresion ../text() is the value of the text in c and the string-length() function gives the number of characters in the text.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:create-path newpath="@size" xpath="/a/b/c" />
          <stm:set-xpath-eval xpath="/a/b[1]/c/@size"> string-length(../text()) </stm:set-xpath-eval>
          <stm:set-xpath-eval xpath="/a/b[2]/c/@size"> string-length(../text()) </stm:set-xpath-eval>
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 2: set-xpath-eval with values from Param

In this example we show param substitution. Any element named <param> within an stm operation element is substituted by the document fragment within the param document at the location given by the <param> xpath attribute. In this case we show how the value substituted from the param is actually into an xpath expression which is then evaluated and the result is placed in the operations xpath target.

In detail, this example does an xpath concatenation to form a string with literals interspersed with values obtained from the param. The targets are the food attributes of /a/b/c

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:set-xpath-eval xpath="/a/b[1]/c/@food"> concat('I like ',.,', but I prefer ','
            <stm:param xpath="/i/j[1]/k/text()" />')
          </stm:set-xpath-eval>
          <stm:set-xpath-eval xpath="/a/b[2]/c/@food"> concat('I likes ',.,' and I will eat ','
            <stm:param xpath="/i/j[1]/k/text()" />,',' but I really prefers ','
            <stm:param xpath="/i/j[2]/k/text()" />')
          </stm:set-xpath-eval>
        </stm:group>
      </operator>
      <param>param.xml</param>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it


1060® NetKernelTM Documentation
(C) 2003-2004 1060 Research Limited

Send Feedback

© 2003,2004, 1060® Research Limited
1060 registered trademark, NetKernel trademark of 1060 Research Limited