14.8.2.4 Using an alternate macro to generate XML
tags
As an alternative, a somewhat simpler version
of macro [ProcIXtext]uses the trim
operator instead of the length operator, and
steps through the index entry character by character; see §28.6.5 Specifying substrings in expressions:
|
[ProcIXtext]
|
|
1
|
<$$IXlevel = 1>
|
|
2
|
<$_while ($$IXtext)>
|
|
3
|
<index<$$IXlevel>>
|
Opening XML tag
|
4
|
<$_repeat>
|
|
5
|
<$_if
($$IXtext is "")><$_break>
|
|
6
|
<$_elseif
(($$IXtext first 3) is "\\:")>
|
Check for colon-as-text
|
7
|
:
|
Text colon output
|
8
|
<$$IXtext
= ($$IXtext trim first 3)>
|
|
9
|
<$_elseif
(($$IXtext first 1) is ":")>
|
|
10
|
<$$IXtext
= ($$IXtext trim first 1)>
|
|
11
|
<$_break>
|
|
12
|
<$_else>
|
|
13
|
<$($$IXtext
first 1)>
|
Text character output
|
14
|
<$$IXtext
= ($$IXtext trim first 1)>
|
|
15
|
<$_endif>
|
|
16
|
<$_endrepeat>
|
|
17
|
</index<$$IXlevel>>
|
Closing XML tag
|
18
|
<$$IXlevel++>
|
|
19
|
<$_endwhile>
|
|
Only one macro required
This version uses <$_repeat>
for the inner loop, which allows the inner loop to be nested in the same
macro, eliminating the need for a second macro; see §28.6.4.3 Using loop structures.
Colons used as text are output on line 7;
all other text is output on line 13,
one character at a time. Surrounding XML tags are output on line 3
and line 17.