code: def css_to_func(css, flags, css_namespaces, lang):
      
      from cssselect import parse, HTMLTranslator
      from cssselect.parser import FunctionalPseudoElement
      #  FIXME HACK need lessc to support functional-pseudo-selectors instead
      #  of marking as strings and stripping " here.
      if not (css):
          return None
  
      sel = parse(css.strip('" '))[0]
      xpath = HTMLTranslator().selector_to_xpath(sel)
  
      first_letter = False
      if sel.pseudo_element is not None:
          if type(sel.pseudo_element) == FunctionalPseudoElement:
              if sel.pseudo_element.name in ('attr', 'first-letter'):
                  xpath += '/@' + sel.pseudo_element.arguments[0].value
                  if sel.pseudo_element.name == 'first-letter':
                      first_letter = True
          elif isinstance(sel.pseudo_element, type(u'')):
              if sel.pseudo_element == 'first-letter':
                  first_letter = True
  
      xp = etree.XPath(xpath, namespaces=css_namespaces)
  
      def toupper(u):
          """Use icu library for locale sensitive uppercasing (python2)."""
          loc = Locale(lang) if lang else Locale()
          return UnicodeString(u).toUpper(loc).encode('utf-8').decode('utf-8')
  
      def func(elem):
          res = xp(elem)
          if res:
              if etree.iselement(res[0]):
                  res_str = etree.tostring(res[0], encoding='unicode',
                                           method="text")
              else:
                  res_str = res[0]
              if first_letter:
                  if res_str:
                      if flags and 'nocase' in flags:
                          return toupper(res_str[0])
                      else:
                          return res_str[0]
                  else:
                      return res_str
              else:
                  if flags and 'nocase' in flags:
                      return toupper(res_str)
                  else:
                      return res_str
  
      return func
docs: Convert a css selector to an xpath, supporting pseudo elements.