Replace user-type text fields that start with "py3o." with genshi
        instructions.

def __prepare_usertexts(self):
        """Replace user-type text fields that start with "py3o." with genshi
        instructions.
        """

        field_expr = "//text:user-field-get[starts-with(@text:name, 'py3o.')]"

        for content_tree in self.content_trees:

            for userfield in content_tree.xpath(
                field_expr,
                namespaces=self.namespaces
            ):
                parent = userfield.getparent()
                value = userfield.attrib[
                    '{%s}name' % self.namespaces['text']
                ][5:]
                value_type = self.field_info[value]['value_type']

                # we try to override global var type with local settings
                value_type_attr = '{%s}value-type' % self.namespaces['office']
                rec = 0
                parent_node = parent

                # special case for float which has a value info on top level
                # overriding local value
                found_node = False
                while rec <= 5:
                    if parent_node is None:
                        break

                    # find an ancestor with an  office:value-type attribute
                    # this is the case when you are inside a table
                    if value_type_attr in parent_node.attrib:
                        value_type = parent_node.attrib[value_type_attr]
                        found_node = True
                        break

                    rec += 1
                    parent_node = parent_node.getparent()

                if value_type == 'float':
                    value_attr = '{%s}value' % self.namespaces['office']
                    rec = 0

                    if found_node:
                        parent_node.attrib[value_attr] = "${%s}" % value
                    else:
                        parent_node = userfield
                        while rec <= 7:
                            if parent_node is None:
                                break

                            if value_attr in parent_node.attrib:
                                parent_node.attrib[value_attr] = "${%s}" % value
                                break

                            rec += 1
                            parent_node = parent_node.getparent()

                    value = "format_float(%s)" % value

                if value_type == 'percentage':
                    del parent_node.attrib[value_attr]
                    value = "format_percentage(%s)" % value
                    parent_node.attrib[value_type_attr] = "string"

                attribs = dict()
                attribs['{%s}strip' % GENSHI_URI] = 'True'
                attribs['{%s}content' % GENSHI_URI] = value

                genshi_node = lxml.etree.Element(
                    'span',
                    attrib=attribs,
                    nsmap={'py': GENSHI_URI}
                )

                if userfield.tail:
                    genshi_node.tail = userfield.tail

                parent.replace(userfield, genshi_node)