I've been googling for answers for a while now but can not seem to find an explanation of how XML namespaces play together between a source XML document and an XSLT.
Here's the situation:
- I have a blog. (http://geekdork.blogspot.com
- The blog has a feed. (http://geekdork.blogspot.com/atom.xml
- I can not affect the feed, it's generated.
- The feed has some nodes with an xmlns attribute defined in them (value is "http://purl.org/atom/ns#"). Example:
I'd like to read in the feed, transform it with an XSLT and display the result on an ASP.NET page. However, I can't seem to get past the namespace issue.
I have saved a copy of the feed locally and have added a reference to an XSLT style sheet to test the layout. I have a single "xsl:template":
That XPath does not work. In my testing on a XPath tester I found I needed to specify the namespace prefix in the query (//ns:entry) in order to get the query to return nodes as expected.
When I bring up the XML document in IE to test the XSLT I get the following error:
"Reference to undeclared namespace prefix".
All variations of the xpath result in this same error. It seems that something is seeing the xmlns attributes in the source XML document and requiring their declaration somewhere.
I've been searching on that exact error string, but still can't seem to find an answer. I just don't understand where in the XSLT I need to declare the namespace for nodes in the source document. I have tried putting a namespace attribute in the style-sheet root node as several pages suggested:
This still didn't work.
I have worked with XML enough to understand XPath queries and have done some XSLT transformations, but it has always been on simpler XML document structures without namespaces.
Can someone explain where I need to define the namespace(s)?