#### 14.8.2.2 Generating XML tags for each level

Check each index entry for colons: level separators that indicate a new index level. When a colon is encountered, close the XML element for the current level, and increment the level number:

| [ProcIXtext] |
1 | <$$IXlevel = 1> |
2 | <$_while ($$IXtext length)> |
3 | <index<$$IXlevel>> | Opening XML tag
4 | <$$IXpart = ($$IXtext before ":")> |
5 | <$$IXpart> | Text
6 | <$$IXpart = ($$IXtext after ":")> |
7 | <$$IXtext = $$IXpart> |
8 | </index<$$IXlevel>> | Closing XML tag
9 | <$$IXlevel++> |
10 | <$_endwhile> |

The unary length operator in line 2 gets the length of the preceding value of variable $$IXtext, so the <$_while> expression works correctly; see:

§28.6.4 Using control structures in expressions

§28.6.5 Specifying substrings in expressions.

Assignment statements by default do not produce output, so only the value of the $$IXpart variable on line 5 actually ends up as content between the XML <index n> tags, which are output on line 3 and line 8; see:

§28.3.2 Assigning values to macro variables

§28.6.3 Displaying expression results in output.

| 14.8.2.1 Configuring macro definitions for easier reading |  | 14.8.2.3 Detecting colons used as text or punctuation |