• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Associating 1 XSL file with many XML files

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
My cellmate was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic