Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : XSLT transform gives invalid XML


Aaron Clauson
6/12/2004 2:19:54 AM
Hi,

I just tried to run a piece of code working with .Net 1.0 after compiling it
with 1.1. It failed and I tracked it down to the XSLT transform method
outputting invalid XML. The problem only seems to occur if the XML has an
html node. When it does so the transform method seems to take it into its
own hands to assume you want non-compliant XML/HTML.

An example:

using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace XMLTransform
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument modelDom = new XmlDocument();
modelDom.LoadXml("<page/>");

XmlDocument transformDom = new XmlDocument();
transformDom.LoadXml(
@"<?xml version='1.0' ?>
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<html>
<body>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>"
);

XslTransform transformStage = new XslTransform();
transformStage.Load(transformDom, null, null);

transformStage.Transform(modelDom, null, Console.Out, null);

Console.ReadLine();
}
}
}

Output:
<html>
<body>
<br>
</body>
</html>

Thanks,
Aaron Clauson

Martin Honnen
6/12/2004 1:19:01 PM


[quoted text, click to view]


[quoted text, click to view]

Use
<xsl:output method="xml" />
if you want XML output, the rules at
http://www.w3.org/TR/xslt#output
clearly state the html is choosen as the output method if you have a
<html> element as the document element of the result tree.
--

Martin Honnen
http://JavaScript.FAQTs.com/
AddThis Social Bookmark Button