stm:apply-ns
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:apply-ns

Apply a Namespace


Attribute
xpathrequired the target xpath into the operand document
prefixrequired prefix identifier to use for namespace uri
urirequired a uri for the namespace

A namespace is a URI associated with a document node which is expressed by a short-hand prefix on the element name. The stm:apply-ns operation applies a namespace to a document fragment located by an xpath reference to an element. The children of the target element are all moved into the namespace. The xmlns: declaration will be made on target element. If the target xpath is multivalued then each fragment will be processed and a namespace declaration will be made on each fragment root element.

Due to the historical difficulty of handling namespaces they have generally been infrequently used by XML applications. STM attempts to make assignment of namespaces straightforward. We anticipate that namespace assigment can be a valuable tool in XML processing. For example portions of an in-process document may be moved into a temporary namespace to hide it from intermediate processing steps before moving it back to the original namespace on completion.

stm:apply-ns is namespace aware, it cannot be used to overwrite an existing namespace. An existing namespace must first be removed before applying a new namepspace, see stm:remove-ns.

Limitations: The current implementation only handles namespace assignment to elements, though this should cover 90% of use cases.

Note: Remember that subsequent operations must use the namespace in any xpath that references these newly namespaced fragment!

Due to the limitations of the DOM model applying namespaces is a relatively expensive operation.

Example

Example 1: Apply a namespace

This example applies a namespace country to the first <b> element and it's children.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:apply-ns prefix="country" uri="http://1060.org/stm/apply-ns/eg1" xpath="/a/b[1]" />
        </stm:group>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try it

Example 2: Apply two different namespaces

This example demonstrates applying two different namespaces to each of the <b> elements in turn. Note both assignments are made to /a/b[1], this is not a mistake, the second assigment is to /a/b[1] since the initial /a/b[1] has become /a/country:b.

<idoc>
  <seq>
    <instr>
      <type>stm</type>
      <operand>doc.xml</operand>
      <operator>
        <stm:group xmlns:stm="http://1060.org/stm">
          <stm:apply-ns prefix="country" uri="http://1060.org/stm/apply-ns/eg1" xpath="/a/b[1]" />
          <stm:apply-ns prefix="seaside" uri="http://1060.org/stm/apply-ns/eg2" xpath="/a/b[1]" />
        </stm:group>
      </operator>
      <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