472,142 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

XML-to-XML XSLT transformation using an intermediate file.

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.
Sep 15 '07 #1
7 2515
Dököll
2,364 Expert 2GB
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
Sep 16 '07 #2
pivote
4
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.
Sep 16 '07 #3
pivote
4
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:


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  try
  4.             {
  5.                 XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
  6.                 xmlReaderSettings.ProhibitDtd = false;
  7.  
  8.                 XmlReader xmlSource = XmlReader.Create("file1.xml", xmlReaderSettings);
  9.                 XPathDocument xpathDoc = new XPathDocument(xmlSource);
  10.  
  11.                 XmlTextReader xslSource = new XmlTextReader("file.xslt");
  12.                 XslCompiledTransform xsltDoc = new XslCompiledTransform();
  13.                 XsltSettings settings = new XsltSettings(true, false);
  14.                 xsltDoc.Load(xslSource,settings, new XmlUrlResolver());
  15.  
  16.                 XmlWriterSettings writerSettings = new XmlWriterSettings();
  17.                 writerSettings.Encoding = System.Text.Encoding.UTF8;
  18.                 writerSettings.OmitXmlDeclaration = false;
  19.                 writerSettings.Indent = true;
  20.  
  21.                 XmlWriter xmlOutput = XmlWriter.Create("file2.xml", writerSettings);
  22.  
  23.                 xmlOutput.WriteDocType("file", null, "file2.dtd", null);
  24.  
  25.                 xsltDoc.Transform(xpathDoc, null, xmlOutput);
  26.  
  27.                 xmlOutput.Close();
  28.  
  29.             }
  30.             catch (Exception e)
  31.             {
  32.                 Console.WriteLine("Excepcion: {0}", e.ToString());
  33.             }
  34.  
  35.  


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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <xsl:output method="xml" version="1" encoding="utf-8" omit-xml-declaration="no" doctype-system="file2.dtd" indent="yes"/>
  3.  


Thank you for your help.
Sep 16 '07 #4
jkmyoung
2,057 Expert 2GB
Does this occur after loading the result xml file or at the end of the transformation?
Sep 17 '07 #5
pivote
4
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.
Sep 19 '07 #6
jkmyoung
2,057 Expert 2GB
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
Sep 19 '07 #7
Dököll
2,364 Expert 2GB
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
Sep 20 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jon Martin Solaas | last post: by
1 post views Thread by Dan | last post: by
4 posts views Thread by =?Utf-8?B?REZC?= | last post: by
2 posts views Thread by Pathik | last post: by
1 post views Thread by =?Utf-8?B?R2xlbm4gR29tZXo=?= | last post: by
1 post views Thread by boetke | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.