Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docx/oxml/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
"""
Custom element classes related to the styles part
"""
from lxml import etree

from ..styles import BabelFish
from ..enum.style import WD_STYLE_TYPE
from .simpletypes import ST_DecimalNumber, ST_OnOff, ST_String
from .xmlchemy import (
BaseOxmlElement, OptionalAttribute, RequiredAttribute, ZeroOrMore,
ZeroOrOne
)

def _xpath_ui2internal(xpath, items):
"""
Return the BabelFish.ui2internal() value when
called from a xpath expression
"""

return [BabelFish.ui2internal(item) for item in items]

etree.FunctionNamespace('')['ui2internal'] = _xpath_ui2internal


def styleId_from_name(name):
"""
Expand Down Expand Up @@ -338,7 +350,7 @@ def get_by_name(self, name):
Return the ``<w:style>`` child element having ``<w:name>`` child
element with value *name*, or |None| if not found.
"""
xpath = 'w:style[w:name/@w:val="%s"]' % name
xpath = 'w:style[ui2internal(w:name/@w:val)="%s"]' % name
try:
return self.xpath(xpath)[0]
except IndexError:
Expand Down