POV-Ray : Newsgroups : povray.off-topic : The trouble with XSLT : Re: The trouble with XSLT Server Time
29 Jul 2024 14:23:45 EDT (-0400)
  Re: The trouble with XSLT  
From: Mike Raiford
Date: 9 Mar 2012 16:00:00
Message: <web.4f5a6e76f77903f464c6b3fb0@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> 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...

I coded one up in C# in about 15 minutes. It doesn't take much if your language
of choice already has a library for handling xml/xslt.

I found this post rather interesting as my current project is one big stylesheet
to turn raw xml into a legible report. I've learned just how powerful the
language is. There's a ton you can do with it, and I now wonder why everyone
always moans and groans about how difficult it is to deal with.


Post a reply to this message

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