rule
translate pattern condition? action*
A translate
rule is a markup rule that allows you to process the data content of elements and attributes, and to process external entities in SGML.
You can write a translate
rule to match patterns within the data-content of a parsed source the way you would write a find
rule to match patterns in a scanned source:
translate "$" digit+ => dollars ("." digit{2} => cents)? output dollars output "," || cents when cents is specified output "$"
Note that, unlike most other markup rules, a translate rule does not have to (and must not) output the parse continuation operator ("%c"). (A translate rule is a scanning action taking place in the context of a parse and not a parsing operation per se.)
Translate rules also apply to attribute values written to output using the "%v"
format item, though not those returned by the attribute
keyword.
For processing SGML SDATA and CDATA entities you can use translate rules with the keywords sdata
and cdata
to match the name or value of the entity.
You can restrict the operation of a translate
rule to a particular element with a condition:
translate "$" digit+ => dollars ("." digit{2} => cents)? when element is "price"
You can turn off translate rules for the content of a particular element by specifying the "z" modifier on "%c":
element "price" output "%zc"
You can turn off translate rules for the content of a particular attribute by specifying the "z" modifier on "%v"
element "price" output "%zv(discount)%zc"
You can turn off translate rules for an entire output stream by opening that stream with the "z" modifier:
open foo with "z" as buffer
#current-input
is unattached in a translate rule.
The effect of any output-to
action in a translate
rule is limited to the translate
rule in which it occurs. It is as if the actions in each translate
rule were wrapped in a using output as #current-output do...done
block.
Like find rules, translate rules do not match across the boundaries of their sources. The source for translate rules is any consecutive run of data content. For instance, given the input:
<p>Mary <b>had</b> a <i>little</i> lamb</p>the rule:
translate "Mary had" output "Jane possessed"will not fire because the phrase "Mary had" is not contiguous data content.
If a comment or a marked section occurs in the text, the comment or marked section does not constitute a source boundary for translate rules unless you capture the comment or marked section with a markup-comment
or marked-section
rule. In other words, if you ignore comments and marked sections, so does OmniMark. If you process them, OmniMark treats them as source boundaries for translate rules.