You need to explain the requirement more clearly.
You have a set of possible paths in some file doctree.xml, yes? And you now want to test whether one of these paths matches some other document, say instance.xml?
Your proposed expression if doc('doctree.xml')//path[.= concat('//',string-join(for $i in (ancestor-or-self::node()[name()]) return $i/local-name(),'/'))]) works entirely within a single document, so it's not clear what it's trying to achieve.
Do you want to know whether all the paths in doctree have a match, or whether a specific one does, or whether a particular node in instance.xml matches one of the paths, or what???
Instead of generating a data file containing paths, why not generate an XSLT stylesheet or XQuery that gives you the answer directly?
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference