GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Associating 1 XSL file with many XML files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Associating 1 XSL file with many XML files" Watch "Associating 1 XSL file with many XML files" New topic
Author

Associating 1 XSL file with many XML files

Eoin Mac Aoidh
Ranch Hand

Joined: May 19, 2005
Posts: 48
Hi,
I am looking for a way to associate an XSL file (which defines how to render a given XML file as HTML) with a batch of XML files. Up until now, I have been dealing with one or two XML files, so it hasnt been a problem to put the line:
"<?xml-stylesheet type="text/xsl" href="****.xsl"?>"
in each of the XML files to associate it with the XSL file ****.xsl.

Now I am faced with potentially thousands of XML files, all of which will be very similar, just with different values. I wish to render them all as HTML using the same .xsl file.
Is it possible to do this simply enough, or do I need to write a short program that will take each xml file, open it, insert the line to link it to my xsl file, save it and close it??? Surely theres an easier way?!

Thanks,

Eoin.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Let's think about that. You choose one of those thousands of XML files, and you send it to a browser. Now, how should the browser know that it should use a certain XSL file from your server to transform it? Well, you already know one way, namely to put in the "xml-stylesheet" processing instruction.

So, you were hoping there was another way for the browser to know it should use that XSL file? Remember that all the browser has to work with is the XML file, nothing else, so it would have to be some other information in the XML file. That's the same problem anyway.

But if you don't want the maintenance headache of putting the PI in every single one of your XML files, you could have an XSLT that inserted it every time you sent an XML file to the browser.

Or you could render the HTML yourself on the server, but perhaps you've already decided against that.
Eoin Mac Aoidh
Ranch Hand

Joined: May 19, 2005
Posts: 48
Hi Paul,
Thanks for your thoughts on this one. Im very new to the XML thing, I have a question -
But if you don't want the maintenance headache of putting the PI in every single one of your XML files, you could have an XSLT that inserted it every time you sent an XML file to the browser.


Im not sure I understand what you were getting at there; Does that mean the transformation to HTML from the original XML file is a two step process. The first transformation Transforms the XML file to a new XML file containing the PI, then the XSL would transform that new XML file to HTML - have I got that right?
Dosnt this give rise to the same problem at the first transformation stage though? Woudnt I need to put a line in the first XML file to tell it how to transform?
Sorry Im a little confused - I hope my questions are clear.
Thanks for your help,

Eoin.
Eoin Mac Aoidh
Ranch Hand

Joined: May 19, 2005
Posts: 48
OK - I think I got it. -Im using javascript to do it.
Anyone else with the same problem, I found the answer here:
http://www.w3schools.com/xsl/xsl_client.asp
This will do the job fine for what I want.
Thanks again Paul.


Eoin.
 
GeeCON Prague 2014
 
subject: Associating 1 XSL file with many XML files