Next / Previous / Contents / Shipman's homepage

4.21. dash(): Attribute set builder

One of the conveniences of the etbuilder module is that keyword arguments to the E() universal element constructor become attributes of the element. So, for example, E("hr", id='c41') gives you the element <hr id='cp1'/>.

Unfortunately, that rarely helps with XSL-FO names, most of which are multiple hyphenated words, and hyphens are an operator in Python.

So the purpose of the dash() function is to build dictionaries of XSL-FO attributes that can be passed to the E() constructor using keyword arguments that are valid Python names that map to valid XSL-FO names.

The trick is to use “camelCase” names on the Python side. This function detects each transition from a lowercase character x to an uppercase character Y, and replaces that with the sequence “x-y”.

Here is the function prototype:


The result is a dictionary with the same elements as kw, but with each “camelCase” transition converted to XSL-FO's multi-word layout. Here's an example:

>>> import fohelpers as h
>>> h.dash(marginTop='2pc', marginBottom='1pc')
{'margin-top': '2pc', 'margin-bottom': '1pc'}