Now a question about the document() function.
I'm trying to do my XSLT transformation on .NET with the XmlCompiledTransform() method. First, it told me that I should change the XsltSettings, because it is not allowed to do the transformation using the document() function on the stylesheet. I changed the settings and now it works. The problem is that I get an error saying that the DTD validation is not enabled for that file (referring to the file accessed with the document function). If I do not write the <!DOCTYPE name SYSTEM "file_name.dtd"> line on the file accessed with the document() function, it works. However, I would like not to erase that line, because I would prefer to do the DTD validation on that file.
Here is my code:
-
-
-
try
-
{
-
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
-
xmlReaderSettings.ProhibitDtd = false;
-
-
XmlReader xmlSource = XmlReader.Create("file1.xml", xmlReaderSettings);
-
XPathDocument xpathDoc = new XPathDocument(xmlSource);
-
-
XmlTextReader xslSource = new XmlTextReader("file.xslt");
-
XslCompiledTransform xsltDoc = new XslCompiledTransform();
-
XsltSettings settings = new XsltSettings(true, false);
-
xsltDoc.Load(xslSource,settings, new XmlUrlResolver());
-
-
XmlWriterSettings writerSettings = new XmlWriterSettings();
-
writerSettings.Encoding = System.Text.Encoding.UTF8;
-
writerSettings.OmitXmlDeclaration = false;
-
writerSettings.Indent = true;
-
-
XmlWriter xmlOutput = XmlWriter.Create("file2.xml", writerSettings);
-
-
xmlOutput.WriteDocType("file", null, "file2.dtd", null);
-
-
xsltDoc.Transform(xpathDoc, null, xmlOutput);
-
-
xmlOutput.Close();
-
-
}
-
catch (Exception e)
-
{
-
Console.WriteLine("Excepcion: {0}", e.ToString());
-
}
-
-
Another question:
It seems that the xml:output line I wrote on my stylesheet doesn't work either. That's why I wrote those settings for the output file. Here is that line of the stylesheet:
-
-
<xsl:output method="xml" version="1" encoding="utf-8" omit-xml-declaration="no" doctype-system="file2.dtd" indent="yes"/>
-
Thank you for your help.