I am trying to parse an XML document to a website, through a XSLT transformation.
However, to make it work I have to use the following XPath:
/*[name()='standards']/*[name() = 'standard']
Why does the following XPath expression not work?
/standards/standard
Your problem is the most FAQ in XPath — search for XPath and default namespace and you’ll find many good answers.
To summarize the problem: XPath interpretes any unprefixed name as belonging to “no namespace”.
Therefore any unprefixed name in any XPath expression, belonging to some default namespace (not the “no namespace”) isn’t selected.
One way to continue to use names in the location steps is to indicate to the XPath processor that a specific prefix, say “x” is associated to the default namespace. Then issue:
In .NET such namespace binding (called “registering of namespace”) is done using the
XmlNamespaceManagerclass. See this complete example.In XSLT, simply define a namespace at a global level, then specify XPath expressions where each element name is prefixed by the prefix so defined.
Here is a small example:
To process the above XML document we have this:
Applying this transformation to the above XML document correctly selects the wanted element and outputs its string value: