Markup within variables

In general, you may only store simple text/values in variables. However it is sometimes useful to be able to store a marked up text fragment and re-use it later in the document. For this purpose TopLeaf allows the special syntax:

<set var="Fragment" copy="content"/>

provided that Scan element content has been set in the current mapping. Using the above command will copy the scanned content including any contained markup into the variable {Fragment}. You can then re-emit the stored fragment in any future mapping.

Any tags or custom markers in the emitted fragment will be processed as normal, except that the ancestry of an emitted tag will be inherited from the new locale. Thus mappings such as para/emph will only be triggered if that relationship still exists when the fragment is finally emitted.

Note that the only things you can do with stored content is emit it, assign it, or test its value. Any internal markup is immediately stripped when testing or assigning (except a direct copy). This is required since structured markup may not appear within attribute values. Thus commands such as:

<set var="Text" string="{Fragment}"/>

or

<if var="Fragment" target="E=mc2">

will strip any contained markup prior to assigning or testing the fragment.

Of course if you want the content markup to be stripped in the first place, just use:

<set var="Fragment" string="{content}"/>

and the {Fragment} variable will be contain a pure text string with any internal markup removed.

[Warning] Warning

Variables containing markup must not be used within attributes in custom markers, or any command other than set, stack, if, while or case. Improper usage can cause unpredictable or inconsistent results.