Converting custom paragraph styles to semantic tags

Converting a custom paragraph style to an XHTML element (possibly having specific attributes) is simple and does not require writing a XED script. Suffice for that to pass parameter blocks.convert to the Edit step.

Example 1.a: convert paragraphs having a “ProgramListing” paragraph style to XHTML element pre:

-p edit.blocks.convert "p-ProgramListing pre"

Notice that the name of paragraph style in the generated XHTML+CSS file is always prefixed by “p-“.

If you use the above blocks.convert specification, it will work fine, except that you’ll end up with several consecutive pre elements (one pre per line of program listing). This is clearly not what you want. You want consecutive pre elements to be merged into a single pre element. Fortunately implementing this too is quite simple.

Example 1.b: convert paragraphs having a “ProgramListing” paragraph style to XHTML element span (having grouping attributes; more about this below):

-p edit.blocks.convert "p-ProgramListing span g:id='pre' g:container='pre'"

When any of the target XHTML elements have grouping attributes (g:id='pre'[7], g:container='pre', in the above example), then w2x_install_dir/xed/blocks.xed automatically invokes the group() command at the end of the conversions. This has the effect of grouping consecutive <span g:id='pre' g:container='pre'> into a common pre parent element.

Given the fact that XED command group() automatically removes grouping attributes when done and that w2x_install_dir/xed/finish.xed discards all useless span elements, this leaves us with clean pre elements containing text[8].

The syntax for the value of parameter blocks.convert is:

valueconversion [ S ‘!’ S  conversion ]*
conversionstyle_spec S XHTML_element_name [ S attribute ]*
style_specstyle_name | style_pattern
style_pattern  → ‘/’ pattern ’/’ | ‘^’ pattern ‘$’
attributeattribute_name ‘=’ quoted_attribute_value
quoted_attribute_value →  “’” value “’” | ‘”’ value ‘”’

Example 3: in addition to what’s done in above example 1.b, convert paragraphs having a “Term” paragraph style to XHTML element dt, convert paragraphs having a “Definition” paragraph style to XHTML element dl and group consecutive dt and dl elements into a common dl parent:

-p edit.blocks.convert "p-Term dt g:id='dl' g:container='dl' !¬
 p-Definition dd g:id='dl' g:container='dl' !¬
 p-ProgramListing span g:id='pre' g:container='pre'"

What if the semantic XHTML created by the Edit step is then converted to DITA or DocBook by the means of a Transform step?

In the case of XHTML elements pre, dt, dd and dl, there is nothing else to do because the stock XSLT stylesheets already support these elements.

The general case which also requires using custom XSLT stylesheets is explained in section The general case.


[7]Any value would do (e.g. g:id=”foo” would have worked as well). Suffice for consecutive elements to be grouped to all have the same g:id attribute.

[8]Unless you specify:

-p edit.prune.preserve "p-ProgramListing"

script w2x_install_dir/xed/prune.xed will cause open lines to be stripped from the generated pre element.