473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2631
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

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

Similar topics

2
by: Wolfgang | last post by:
I'm applying a simple XSLT style sheet to an XML file. The style sheet is: http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/access-report.xsl The XML file is here: ...
2
by: Jon Martin Solaas | last post by:
For java programmers there exist a framework called Millstone (www.millstone.org) for programming web user-interfaces in a component oriented way. Millstone uses xslt transformations to render...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
1
by: Dan | last post by:
I have a C# program which executes some XSLT transformations. The XSLT code requires an input intermediate file, generated by other transformations, as its duty is copying some data from an input...
4
by: =?Utf-8?B?REZC?= | last post by:
Within an XSLT transformation, I'm trying to switch the default namespace within a section of the generated XML document to a shared namespace. This way, the content of this section does not have...
2
by: Pathik | last post by:
Hi All, I am New to xml. Currently I am trying to transform one xml file to another file using xslt my xml file is as follows: <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet...
1
by: =?Utf-8?B?R2xlbm4gR29tZXo=?= | last post by:
Does Office Excel 2000 support XSLT transformation of data from XML cause am having problem when the attachment is opened in the client side if the Excels version is in Office 2000 and also its...
2
by: groo78 | last post by:
Hi, I have an XML document that I need to convert to XHTML and I would like to use XSLT. I have attempted transformations using javascript and it works fine. The problem I have is that I need...
1
by: boetke | last post by:
Hi all, I am attempting to create an xslt transformation which I am having trouble with. I am fairly new to xslt and am having a hard time getting my head around it. The original xml file looks...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.