Look what's going on:
1) When you want to match the element "foo" by using name() function, the XSLT processor tries to find an element in the source XML document whose element type
literally equals to "foo" (by the way this approach is not safe and must be avoided when possible, since there are issues concerned with namespaces, but not directly concerned the issue you've arisen here). So, the processor sees an element whose element type is "foo" and outputs "A".
2) When you want to match the element by
, the XSLT processor tries to find an element having element type "foo" which is in so called "null" namespace(that is which isn't in any namespace). Since the "foo" element is in the namespace identified by the URI "http://foo/bar", no match is found.
-----
I think the default namespace declaration in your stylesheet confused you. It has no connection with the source XML doc at all and doesn't influence any pattern in template matchings.
There are 2 solutions:
1. you can remove the default namespace declaration in the source XML(also in the stylesheet since it has nothing to do there) or change it to
xmlns="", which are equivalent, and you'll get the output you want.
2.
a) change the namespace declaration in the source XML doc as following:
Code:
<bar:foo xmlns:bar="http://foo/bar" name="A"/>
b) change the namespace declaration in the stylesheet:
[code]
xmlns:bar="http://foo/bar"
[code]
c) change the "match" attribute value: "bar:foo"
Regards,
Armen