check namespace for a node
How to check if namespace exists or not for an element ?开发者_Python百科
How to check if namespace exists or not for an element ?
This question isn't quite clear. In XML (+namespaces) every node has at least two namespaces -- with reserved prefixes "xml" and "xmlns")
I interpret the question to mean:
How to check if a node is in a namespace.
Solution:
not(namespace-uri() = "")
this expression is true()
exactly when the current node is in a namespace and false()
otherwise.
A namespace always exists - it might be the default one, but it will exist.
Properly speaking, a QName is a tuple (namespace URI, local name, prefix).
For node types other than elements and attributes, namespace URI and prefix are empty.
For an element under a no null (or empty) default namespace URI, only prefix is empty.
All attributes with empty prefix have empty namespace URI.
Each item can be selected with these expressions:
namespace-uri($node)
local-name($node)
substring-before(name($node),':')
精彩评论