## 14.5 Converting FrameMaker lists to generic XML

Just converting an unstructured FrameMaker list to XML provides nothing except XML tags around each list item. Autonumbers are converted to text. Bullets become entity references. List properties you would supply for HTML have no meaning in XML.

Suppose you want to convert FrameMaker autonumbered lists that use paragraph formats such as StepFirst and StepNext; and suppose you want the lists to be structured like this in XML:

<steplist>

<stepitem>

<steptext value="1">Text of first step.</steptext>

</stepitem>

<stepitem>

<steptext value="2">Text of second step.</steptext>

</stepitem>

. . .

</steplist>

You can remove the FrameMaker autonumbers by assigning property NoAnum to the step formats, and instead use a macro variable ($$StepNum in the following examples) as a counter to generate step numbers. Assign CodeBefore and CodeAfter properties to both formats, so you can surround the text with XML tags. Also assign NoPara to suppress any HTML <p> tags:

[HtmlStyles]

; Remove the autogenerated numbers:

StepFirst=CodeBefore CodeAfter NoAnum NoPara

StepNext=CodeBefore CodeAfter NoAnum NoPara

; Make sure all non-step formats can close the list:

*=CodeBefore

Assign code to both formats to surround the text with XML tags. If you are not using a list-ending format in FrameMaker (such as StepLast), you must provide a list-closing tag in code that immediately precedes any non-step format. Therefore, all non-step paragraph formats must have the CodeBefore property; thus the final wildcard setting in [HtmlStyles].

Provide code to start the list, start each list item, and start the list-item counter:

[StyleCodeBefore]

; Start the list:

StepFirst=<steps>\n<stepitem><$$StepNum = 1><steptext value="1">

; Start each list item:

StepNext=<stepitem><steptext value="<$$StepNum++ as %s>">

; End the list before the first non-list paragraph:

*=<$_if ($$StepNum)></steps>\n<$$StepNum = 0><$_endif>

Whenever a non-step paragraph is encountered, if a list was in progress, the last setting in [StyleCodeBefore] provides closing XML tags for it, and resets the step counter.

If you have more than one paragraph in any step, you have more work to do; you must provide explicit “before” and “after” code for each paragraph format that appears within a list, to prevent those formats from terminating the list. Or, you could use a StepLast format for the final item in each list, and avoid this problem.

The “after” code for each paragraph format in the list provides the closing XML tags:

[StyleCodeAfter]

; End each list item:

Step*=</steptext></stepitem>

If you use a StepLast format, you could end the list with it here, instead of using the wildcard settings in [StyleCodeBefore]. You would place the following setting ahead of the Step* setting in [StyleCodeAfter]:

StepLast=</steptext></stepitem></steplist>\n<$$StepNum = 0>

To account for the possibility that a list item is the very last paragraph in a document, check for a list at the very end:

[Inserts]

; This handles the case where a list ends the document:

End = <$_if ($$StepNum)></steplist>\n<$$StepNum = 0><$_endif>

Again, if you consistently use a StepLast format, you can omit the [Inserts]End setting.

Because the wildcard setting in [StyleCodeBefore] most probably tests the value of $$StepNum before any other code has a chance to assign a value to this variable, you must explicitly give it a starting value:

[MacroVariables]

; Because you test before you set, you must initialize $$StepNum:

StepNum = 0

Again, if you use a StepLast format, you can omit this setting.

| 14.4.5 Configuring forced returns for XML |  | 14.6 Configuring links for generic XML |