def xml_translate(callback, value):
 if (not value):
  return value
 trans = XMLTranslator(callback, 'xml')
 try:
  root = etree.fromstring(encode(value))
  trans.process(root)
  return trans.get_done()
 except etree.ParseError:
  wrapped = ('<div>%s</div>' % encode(value))
  root = etree.fromstring(wrapped, etree.HTMLParser(encoding='utf-8'))
  trans.process(root[0][0])
  return trans.get_done()[5:(-6)]

def xml_translate ( callback , value ) : if ( not value ) : return value trans = XMLTranslator ( callback , 'xml' ) try : root = etree . fromstring ( encode ( value ) ) trans . process ( root ) return trans . get_done ( ) except etree . ParseError : wrapped = ( '<div>%s</div>' % encode ( value ) ) root = etree . fromstring ( wrapped , etree . HTMLParser ( encoding = 'utf-8' ) ) trans . process ( root [ 0 ] [ 0 ] ) return trans . get_done ( ) [ 5 : ( - 6 ) ]
translate an xml value .