I use this code to transform XML to HTML using XSLT template:
string uri = Server.MapPath("~/template.xslt");
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(uri);
XDocument xml = new XDocument(new XElement("Root"));
StringBuilder builder = new StringBuilder();
XmlReader reader = xml.CreateReader();
XmlWriter writer = XmlWriter.Create(builder, xsl.OutputSettings);
xsl.Transform(reader, writer);
writer.Close();
My template looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes" />
<xsl:template match="Root">
<html>
<head>...
Output is correct however it contains META tag. How to disable transform so it would not generate META tag?
The XSLT 1.0 specification for output method=”html” (http://www.w3.org/TR/xslt#section-HTML-Output-Method) mandates that a meta element is output if there is a head section in the result tree:
So XslCompiledTransform does what an XSLT processor should do. If you don’t want the meta element you will need to explain in more detail what kind of output you want exactly or why the meta is a problem if you want html output. You could of course use output method=”xml”, that way you won’t get the meta element but I am not sure the serialization result that way will be what you want for stuff like ‘br’ element nodes.