Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

delete nodes

Syntax:

Code Block
languagexml
delete node location

...

Code Block
languagexml
delete nodes location 

The expression location represents expression location represents a sequence of nodes which are marked for deletion (the actual number of nodes does not need to match the keyword node or nodes).

insert nodes

Syntax:

Code Block
languagexml
insert (node|nodes) items into path

...

  • If either form of into is used, then the target node must be an element or a document. The items to insert are treated exactly as the contents of an element constructor.

    For example if $target points to an empty element <CONT/>,

    Code Block
    languagexml
    insert nodes (attribute A { 5.4 }, <child1/>, "text", 2 to 4) 
    into $target
    yields:
    Code Block
    languagexml
    <CONT A="5.4"><child1/>text 2 3 4</CONT>

    Therefore the same rules as in constructors apply: item order is preserved, a space is inserted between consecutive non-node items, inserted nodes are copied first, attribute nodes are not allowed after other item types, etc.

  • When the keywords as first (resp. as last) are used, the items are inserted before (resp. after) any existing children of the element.

    For example if $target points to an element <parent><kid/></parent>

    Code Block
    languagexml
    insert node <elder/> as first into $target

    yields:

    Code Block
    languagexml
    <parent><elder/><kid/></parent>

    When the only keyword into is used, the resulting position is implementation dependent. It is only guaranteed that as first into and as last into have priority over into.

  • If before or after are used, any node type is allowed for the target node.

  • Attributes are a special case: regardless of the before or after keyword used, attributes are always inserted into the parent element of the target. The order of inserted attributes is unspecified. Name conflicts can generate errors.

replace node

Syntax:

Code Block
languagexml
replace node location with items

The expression location must expression location must point to a single target node.

...

  • Except for document and attribute node types, the target node can be replaced by any sequence of items. The replacing items are treated exactly as the contents of an element/document constructor.

    For example if $target points to an element <P><kid/>some text</P>,

    Code Block
    languagexml
    replace node $target/kid with "here is" 

    yields:

    Code Block
    languagexml
    <P>here is some text</P>


  • Attributes are a special case: they can only be replaced by an attribute node. Name conflicts can generate errors.

replace value of node

Syntax:

Code Block
languagexml
replace value of node location with items

Here the identity of the target node is preserved. Only its value or contents (for an element or a document) is replaced.

  • If the target is an element or a document node, then all its former children are removed and replaced. The replacing items are treated exactly as the contents of a text constructor (so all node items are replaced by their string-value).

    For example if $target points to an element <P><kid/>some text</P>,

    Code Block
    languagexml
    replace value of node $target with (<text>let's count: </text>, 1 to 3, "...") 
    yields:
    Code Block
    languagexml
    <P>let's count: 1 2 3 ...</P>


    So the element contents are replaced by a text node whose value is the concatenation of the string values of replacing items.

  • If the target node is a leaf node (attribute, text, comment, processing-instruction) then its string value is replaced by the concatenation of the string values of replacing items.

    For example if $target points to an element <P order="old">some text</P>,

    Code Block
    languagexml
    replace value of node $target/@order with (1 to 3, <ell>...</ell>) 

    yields:

    Code Block
    languagexml
    <P order="1 2 3...">some text</P>


rename node

Syntax:

Code Block
languagexml
rename node location as name-expression

The expression location must expression location must point to a single target element, attribute or processing-instruction.

...

For example if $target points to an element <CONT AB="ab">some text</CONT>

Code Block
languagexml
rename node $target as qName("some.namespace", "CONTAINER"),
rename node $target/

...

B as "

...

NEWB"

yields:

Code Block
languagexml
<ns1:CONTAINER 

...

NEWB="

...

b" xmlns:ns1="some.namespace">some text</ns1:CONTAINER>


transform

Syntax:

Code Block
languagexml
copy $var := node [, $var2 := node2 ...] 
modify updating-expression 
return expression

Each node expression is copied (at least virtually) and bound to a variable.

...

For example if $target points to an element

Code Block
languagexml
copy $target := <CONT id="

...

001">some text</CONT>
modify (
   rename node $target as "SECTION",
   insert node <TITLE>The title</TITLE> as first into $target
)
return element DOC { $target }

returns:

Code Block
languagexml
<DOC><SECTION id="

...

001"><TITLE>The title</TITLE>some text</SECTION></DOC>