def find_xincludes(doc)
     if has_xinclude?(doc)
       xincs = doc.find('//xi:include', "xi:"+XINCLUDE_NS)
       xfiles = xincs.map {|x| x.attributes['href'] }
       (xfiles << xfiles.map {|xf|
                    xfn = File.exists?(xf) ? xf : File.expand_path(xf,File.dirname(doc.root.base_uri))
                    xdoc = XML::Document.file(xfn)
                    find_xincludes(xdoc)
                  }).flatten
     else
       []
     end
   end
def find_xincludes(doc)
     if has_xinclude?(doc)
       xincs = doc.find('//xi:include', "xi:"+XINCLUDE_NS)
       xfiles = xincs.map {|x| x.attributes['href'] }
       (xfiles << xfiles.map {|xf|
                    xfn = File.exists?(xf) ? xf : File.expand_path(xf,File.dirname(doc.root.base_uri))
                    xdoc = XML::Document.file(xfn)
                    find_xincludes(xdoc)
                  }).flatten
     else
       []
     end
   end
Finds and returns all XInclude files/URLs in a document.

 OPTIMIZE implement xpointer and fallback handling for
 xi:include? see http://www.w3.org/TR/xinclude/