Skip to main content

Question about xmlns and xmlns:xhtml

1 reply [Last post]
Joined: 2008-09-08

Hello Guys,

i am trying to parse the following xml file with 'xmlns' and 'xmlns:xhtml' attributes.
I donot get any result parsed with my '.xsl'



But when i remove the "xmlns" and "xmlns:xhtml" attributes, then i am able to parsed xml data in my xsl file. I am using JAXP. Can anyone explain what "xmlns" and "xmlns:xhtml" attributes are for.?

Please respond.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-12-15

Those are namespaces. Namespaces are declared as xmlns:prefix=uri, while xmlns without ":" serves as default namespace. In the xml instance in your case, all elements that are without a prefix belong to the default namespace.

When the target xml document has a default namespace, it needs to be matched with that in the stylesheet. In order to match "method" in the stylesheet, you would have to specify a default namespace in the stylesheet too. But xpath does not allow empty prefix. So in the stylesheet, you would have to provide a prefix, e.g.


and then be able to write xpath query like: match="servlet:method" to match the "method" element.

Hope it works for you.