code: def __xinclude_lxml(target, source, env):
      
      from lxml import etree
      
      doc = etree.parse(str(source[0]))
      doc.xinclude()
      try:
          doc.write(str(target[0]), xml_declaration=True, 
                    encoding="UTF-8", pretty_print=True)
      except:
          pass
  
      return None
docs: Resolving XIncludes, using the lxml module.