I have an xml file and an xslt file.
The xml file has a xmlns=”exa:com.test” attribute.
If i remove this attribute in the xml the xpath sentences in my xslt works. But if i leave it, doesnt work.
Im using the following code to mix xml and xslt:
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(HttpContext.Current.Server.MapPath("xslt\\searchresults.xslt"));
transformer.Transform(xmlreader, null, utf8stringwriter);
What im doing wrong? How could i mix xml and xslt if the xml has the xmlns attribute on top?
The
xmlnsattribute without prefix name replaces the default namespace, so that your query matches nodes with a different (empty) namespace. You need to use a prefixed namespace in the XSLT XPath queries (or aXmlNamespaceManagerfor isolated XPath queries) and your queries will work again as expected.In the XSLT:
Then, assuming that you used to match for instance
xyz, you now change your query like this:In general you might want to read some docs on XML namespaces.