Is there some sort of limitation or syntax quirk that's required to match/parse xmlns attributes with XPath?
Yes, kind of. The quirk is that things like
xmlns:m="..."
syntactically are attributes, but serve a more specific role than attributes. They are namespace declarations that bind prefixes to a namespace URI. The prefixes can then be used to qualify element and attribute names. There is also a default namespace that is not bound to a prefix.
It is impossible to detect namespace declarations because XPath (and XSLT, and Schematron) do not operate on actual XML documents, but on abstract representations of them. In this representation (a model), namespace declarations are absent, but there are namespace nodes which indirectly point to namespace declarations.
Once an XML parser has processed an XML document, namespaces and attributes are distinct types of nodes that you can access with XPath axes. I am not sure I understand why you would want to do that, but you can report namespace nodes using the namespace::
axis:
namespace::*[not(. = 'http://www.w3.org/XML/1998/namespace')]
You have to be careful and exclude the predefined namespace URI
http://www.w3.org/XML/1998/namespace
which is bound to the xml:
prefix by default.
ISO Schematron
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:pattern>
<sch:rule context="node">
<sch:report test="namespace::*[not(. = 'http://www.w3.org/XML/1998/namespace')]">Namespace node found!</sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>
The document you show will not be valid against this SCH file and the Schematron validator will point to the node
element with the namespace declaration:
<node xmlns:m="http://google.com"/>
as the source of the error.
Please Note
The namespace::*
axis selects namespace nodes, not namespace declarations. Since namespaces are inherited by all elements that are in scope, it is not only the element where the namespace is declared that has a namespace node. All of its descendants will also have a namespace node:
<root>
<node xmlns:m="http://google.com">
<descendant_element_with_namespace_node/>
</node>
<node style="block"/>
</root>
See LarsH's answer for a more sophisticated XPath expression that accounts for this fact.