You will not be able to do lots of changes to the code provided in the answers to the linked question provided by Michael Kay and Dimitre Novatchev.
This code (also theirs) touches each node (elements and attributes) exactly once, so runtime for everything inside distinct-values()
is O(n)
on the number of nodes. In worst case, each node has some namespace attached, so you will have to sort these n nodes which is O(n*log n)
for any reasonable sort algorithm.
(: each namespace:uri-combination only once :)
distinct-values(
(: analyze all nodes with namespace set, both attributes and elements :)
/descendant-or-self::*/(.|@*)[namespace-uri(.)]
(: build result string :)
/concat(
substring-before(name(), ':'), ': ', namespace-uri(.), '
'
)
)