473,390 Members | 1,600 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,390 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 2634
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.