tags:

views:

32

answers:

1

How can I omit all XML-Namespaces from the xslt in the html-output?

My XSL starts with:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"&gt;

and my code to transform the XML is as follows

StringBuilder sb = new StringBuilder(600);
XslCompiledTransform xslTrans = new XslCompiledTransform();

xslTrans.Load(XslDoc);//loads the XSL

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.OmitXmlDeclaration = true;
writerSettings.ConformanceLevel = ConformanceLevel.Auto;
writerSettings.NamespaceHandling = NamespaceHandling.OmitDuplicates;


using (XmlWriter stringWriter = XmlWriter.Create(sb, writerSettings))
{
    xslTrans.Transform(XmlDoc, xslArguments, stringWriter);
}
return sb.ToString();

But in the generated html output appear the namespaces as follows:

<div class="newsFeed" xmlnsxs="http://www.w3.org/2001/XMLSchema" xmlnsfn="http://www.w3.org/2005/xpath-functions" >

How can I omit all namespaces in the generated output? It was cool, if I could do this by modifying the XSL, so user can change their XSL to embed their namespaces but default it would be clean HTML-Code without xmlns.

+2  A: 

You're probably looking for the exclude-result-prefixes attribute on your xsl:stylesheet element.

mwittrock
It works perfectly. exclude-result-prefixes is a whitespace-separated list of all namespaces.
Lord Vader
Glad to hear it.
mwittrock