def parse_style(document, xmlcontent):
    """Parse styles document.

    Styles are defined in file 'styles.xml'.
    """

    styles = etree.fromstring(xmlcontent)

    _r = styles.xpath('.//w:rPrDefault', namespaces=NAMESPACES)

    if len(_r) > 0:
        rpr = _r[0].find(_name('{{{w}}}rPr'))

        if rpr is not None:
            st = doc.Style()
            parse_previous_properties(document, st, rpr)
            document.default_style = st

    # rest of the styles
    for style in styles.xpath('.//w:style', namespaces=NAMESPACES):
        st = doc.Style()

        st.style_id = style.attrib[_name('{{{w}}}styleId')]

        style_type = style.attrib[_name('{{{w}}}type')]
        if style_type is not None:
            st.style_type = style_type

        if _name('{{{w}}}default') in style.attrib:
            is_default = style.attrib[_name('{{{w}}}default')]
            if is_default is not None:
                st.is_default = is_default == '1'

        name = style.find(_name('{{{w}}}name'))
        if name is not None:
            st.name = name.attrib[_name('{{{w}}}val')]

        based_on = style.find(_name('{{{w}}}basedOn'))

        if based_on is not None:
            st.based_on = based_on.attrib[_name('{{{w}}}val')]

        document.styles.styles[st.style_id] = st

        if st.is_default:
            document.styles.default_styles[st.style_type] = st.style_id

        rpr = style.find(_name('{{{w}}}rPr'))

        if rpr is not None:
            parse_previous_properties(document, st, rpr)

        ppr = style.find(_name('{{{w}}}pPr'))

        if ppr is not None:
            parse_paragraph_properties(document, st, ppr)
def parse_style ( document , xmlcontent ) : styles = etree . fromstring ( xmlcontent ) _r = styles . xpath ( './/w:rPrDefault' , namespaces = NAMESPACES ) if len ( _r ) > 0 : rpr = _r [ 0 ] . find ( _name ( '{{{w}}}rPr' ) ) if rpr is not None : st = doc . Style ( ) parse_previous_properties ( document , st , rpr ) document . default_style = st for style in styles . xpath ( './/w:style' , namespaces = NAMESPACES ) : st = doc . Style ( ) st . style_id = style . attrib [ _name ( '{{{w}}}styleId' ) ] style_type = style . attrib [ _name ( '{{{w}}}type' ) ] if style_type is not None : st . style_type = style_type if _name ( '{{{w}}}default' ) in style . attrib : is_default = style . attrib [ _name ( '{{{w}}}default' ) ] if is_default is not None : st . is_default = is_default == '1' name = style . find ( _name ( '{{{w}}}name' ) ) if name is not None : st . name = name . attrib [ _name ( '{{{w}}}val' ) ] based_on = style . find ( _name ( '{{{w}}}basedOn' ) ) if based_on is not None : st . based_on = based_on . attrib [ _name ( '{{{w}}}val' ) ] document . styles . styles [ st . style_id ] = st if st . is_default : document . styles . default_styles [ st . style_type ] = st . style_id rpr = style . find ( _name ( '{{{w}}}rPr' ) ) if rpr is not None : parse_previous_properties ( document , st , rpr ) ppr = style . find ( _name ( '{{{w}}}pPr' ) ) if ppr is not None : parse_paragraph_properties ( document , st , ppr )
Parse styles document.

    Styles are defined in file 'styles.xml'.