XML-to-XML XSLT transformation using an intermediate file. | Newbie | | Join Date: Sep 2007
Posts: 4
| | |
I'm trying to transform a XML file to another XML file. The first file must describe what I want to say in a more abstract way than the second. But in order to do the transformation, I need an intermediate XML file which helps to find that more detailed description needed for the output file.
I was wondering if this could be done using XSLT language. I'm quite new to XML and for what I have read, the XSLT transformation just deals with one input file and another output file.
I would appreciate any kind of help. Thanks in advance.
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: XML-to-XML XSLT transformation using an intermediate file. Quote:
Originally Posted by pivote I'm trying to transform a XML file to another XML file. The first file must describe what I want to say in a more abstract way than the second. But in order to do the transformation, I need an intermediate XML file which helps to find that more detailed description needed for the output file.
I was wondering if this could be done using XSLT language. I'm quite new to XML and for what I have read, the XSLT transformation just deals with one input file and another output file.
I would appreciate any kind of help. Thanks in advance. Try this link: http://www.w3schools.com/xsl/xsl_transformation.asp
Please write if additional help is needed...
Good luck!
Try this as well: http://www.w3schools.com/xsl/xsl_editxml.asp | | Newbie | | Join Date: Sep 2007
Posts: 4
| | | re: XML-to-XML XSLT transformation using an intermediate file.
I searched a little bit more and I found that what I was looking for was something similar to using the function document() in the stylesheet in order to call the external document.
Even so, thank you very much for your advice.
| | Newbie | | Join Date: Sep 2007
Posts: 4
| | | re: XML-to-XML XSLT transformation using an intermediate file.
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.
| | Moderator | | Join Date: Mar 2006
Posts: 1,103
| | | re: XML-to-XML XSLT transformation using an intermediate file.
Does this occur after loading the result xml file or at the end of the transformation?
| | Newbie | | Join Date: Sep 2007
Posts: 4
| | | re: XML-to-XML XSLT transformation using an intermediate file.
I don't really understand what you mean, but it occurs when I don't write those settings for the XmlWriter and when I open the file2.xml after the transformation. That file doesn't have the xml declaration and all the other settings. I think that it had to work even if I didn't write those settings because I actually have that line with the xml:output saying the same thing. Thank you very much.
| | Moderator | | Join Date: Mar 2006
Posts: 1,103
| | | re: XML-to-XML XSLT transformation using an intermediate file.
If you're using an XmlReader to validate the file, the XmlReaderSettings in the reader must be set to accept DTD.
See http://msdn2.microsoft.com/en-us/lib...ationtype.aspx |  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: XML-to-XML XSLT transformation using an intermediate file. Quote:
Originally Posted by pivote Now a question about the document() function. [HTML]
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());
} [/HTML]
my stylesheet doesn't work either... [HTML]
<xsl:output method="xml" version="1" encoding="utf-8" omit-xml-declaration="no" doctype-system="file2.dtd" indent="yes"/> [/HTML]
Thank you for your help. Quite welcome...
I can research this for you, pivote, would be my pleasure, pretty good at researching stuff that nature; not an expert at writing it though, but getting there:-)
In a bit, pivote, and thanks for your patience!
Dököll
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|