POV-Ray : Newsgroups : povray.off-topic : The trouble with XSLT : The trouble with XSLT Server Time
29 Jul 2024 08:24:42 EDT (-0400)
  The trouble with XSLT  
From: Invisible
Date: 20 Feb 2012 11:21:03
Message: <4f4272ef@news.povray.org>
OK, so I've written a program that generates a bunch of XML as output. 
If you open that in a web browser, it shows up as a simple parse tree. 
Which is OK, but a little verbose.

Fortunately, using the wonders of XSL (specifically, XSLT) you can have 
the browser transform the raw XML into a pretty-looking XHTML document.

But *only* if you edit the original XML file to mention the XSLT file 
that you want to apply.

Now, it ought to be simple to write a 3-line file that says "take this 
XML file and that XSLT file, and display the result". But after over a 
week searching the Internet and even consulting Stack Overflow, I cannot 
find any way of doing this. I literally cannot *believe* that something 
so trivially simple is also so utterly impossible.

If there /is/ a way of doing this, every single XSL tutorial in 
Christendom fails to mention it. No XSL FAQs mention it either - it's 
not even that they say it can't be done, it's that none of them even 
contain a question about this topic. This raises the alarming 
possibility that what I'm trying to do might actually be impossible 
after all. (Which is slightly daft, given that it's the entire point of 
XSL existing in the first place...)

To be clear: It seems to be perfectly possible to apply any XSL to any 
XML if you use an external 3rd-party tool. You just can't do it with a 
*web browser*. You know, those programs that know about XML and XSL and 
are installed on every computer in the world. No, you have to select and 
download a special CLI utility if you want to perform such advanced 
wizardry. *sigh*

My first thought: XSL lets you include one stylesheet inside another, so 
maybe you can include one source document inside... erm, no. No you can't.

It looks like it /might/ be plausible to do something with the XSL 
document() function - but I haven't figured out exactly how yet.

Apparently XML itself has a general include feature called XInclude. 
According to Wikipedia, "Browser support: None". *facepalm* OK, so 
that's really going to help then.

About the closest thing I've found is a website that says that if you 
copy and paste a few miles of convoluted JavaScript code, you can make a 
web page that runs the script which then loads the required XML in the 
background, lots the XSL, applies one to the other, and inserts the 
result into a specific position in the DOM of the current document. In 
particular, it cannot /replace/ the current document, it can only be 
/inserted into/ it. So if your XSL generates an entire XHTML document... 
forget it.

(I presume it goes without saying that the first thing this code snippet 
has to do is test whether it's running on Internet Explorer or a 
standards compliant browser. :-P Some things never change...)

So it looks like I'm going to have to sit down and write a special tool 
to take an XML file and copy it, inserting the correct XSL reference 
into the header. How pathetic...


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.