XML Script logo
_data and _eval tag - advanced operation
Usage

Both the _data and _eval tags, in their default modes, take the content of their tags and attempt to parse it into XML elements. The _data tag does not check for interpolations by default, whereas the _eval command does check for and honour interpolations. This behaviour can be overridden using the 'interpolate' attribute.

At this point, the _data tag evaluates its content and appends it, without the top-level text, onto the data tree at the current node. It does not run any XML Script command tags it finds there, but treats them as data elements instead.

The _eval tag's default mode differs in two ways: first, it runs any XML Script it finds in its parsed content, processing _if loops etc; second, it turns the resulting output into just that, output. If, for example, an _eval producess a foo element, there is no way of investigating that foo element later on: \# $\foo \# will return nothing.

This is just a restriction on the default modes. Several attributes exist for the _data and _eval tag, that are only revealed by setting result="" for either tag. Then one can use the persist, repeat and side attributes for more control over the way that elements are manipulated.

A good example of this is the persist tag. _eval has persist set to "no" by default: not only are the elements unreferenceable, but, by the time you go through e.g. a sub-template again, they have disappeared, turned into output. Persist="yes" delays their output until the very end of the template, and in the meantime, you can delete them, reference them, change their content... exactly the same as normal template-side elements.

_data with persist set to "no" has the expected result: once you leave the template you're currently in, the data disappears from the node you put it at. This also works for _eval side="data"; the test given below uses this instead, because of context conflicts (see below).

An important point about context: _data sets both template and data trees to be momentarily the same: both are the data tree within the context of _data tags. And if _eval is evaluating an element that has a method associated with it, it runs the element through the required template (so far business as normal) but within that sub-template, both the data and the template trees are... the template tree.

On the template side you can see a tree of the form $(XST)\__doc\CURR-ELEMENT\TEMPLATENAME (where __doc is a temporary tag that _eval puts around its content to aid parsing), whilst on the data side you will have merely (XST)\__doc\CURR-ELEMENT : the current template element is the sub-template we're using for processing; the current data element is the one being processed.

How is this important? Well, interpolations might not do what you want to do: for a start, you can't see the data tree at all within the sub-template above: any "data-side" interpolations you do will bring in elements from the template-side instead. Also, you might add data elements onto the template-side, because, in the current context, data-side is template side. Then, when you leave the sub-template, you can't find them again.

This has advantages, too: if you can force a context where both sides are data-side then you can change the element you're working on, data-side, with a _foreach loop, but then chase up the template-side and find the original element you were working on. While these contexts are very difficult to reproduce within the test suite packaged with X-Tract, if you _process a parent element, whose children have _templates associated with them using _method, then within the _templates all you can see is data-side.

All of that sounds a little complicated: the tests below should show this a little better: ...__tag, $...__tag and so on should show you the parents of the elements you're working with on both data- and template-side. If you're ever in doubt as to whereabouts you are throwing your data, use these attributes (with _output type="console") along with ($).__path to chart your way around the trees. Note that, within templates, your root is often set to the template element, or the element being processed, so \# \.__tag \# will not necessarily return the __data_root.

Examples

_eval vs. the template: real and virtual elements

Deleting a persist="yes" template element

Non-persisting data disappears

_data tags: both sides data-side

_eval - interpolation set to no

Version

1.0

Ref

t.50

Date

17 August 1999

XML Script homepage | Documentation home | XML Script docs | Command list | Function list | X-Tract docs

X-Stream, X-Tract and XML Script are trade marks of DecisionSoft Limited
© Copyright 1998-2000 DecisionSoft Limited