POV-Ray : Newsgroups : povray.off-topic : The trouble with XSLT Server Time
29 Jul 2024 18:19:44 EDT (-0400)
  The trouble with XSLT (Message 1 to 10 of 84)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: The trouble with XSLT
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

From: Invisible
Subject: Re: The trouble with XSLT
Date: 20 Feb 2012 11:58:12
Message: <4f427ba4$1@news.povray.org>
On 20/02/2012 04:21 PM, Invisible wrote:

> (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...)

Oh dear God...

https://bugzilla.mozilla.org/show_bug.cgi?id=98168

Short story: Using the xsl:text disable-output-escaping='yes' setting 
doesn't work. It's supposed to allow you to output arbitrary text, and 
it works with IE, but not with Firefox. And it appears they're trying to 
claim it's IE that's broken, not Firefox. >_<


Post a reply to this message

From: Le Forgeron
Subject: Re: The trouble with XSLT
Date: 20 Feb 2012 12:13:54
Message: <4f427f52$1@news.povray.org>
Le 20/02/2012 17:21, Invisible nous fit lire :

XML failed to have include.

> 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...

That's merely a shell-script:
1. find the closing of the first <?xml tag
2. insert your xsl tokens
3. copy verbatim the remaining document
4.
5. Profit.

Notice: some browser (including firefox), would:
 a. process differently a document from a http:// URL than a file:// URL
 b. not take into account XSL (as well as XSD and CSS, IIRC) not from
the same server as the original document (arguing about security!)


Post a reply to this message

From: Warp
Subject: Re: The trouble with XSLT
Date: 20 Feb 2012 12:43:44
Message: <4f428650@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> 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.

  I don't understand. This in an XML file seems to work just fine (at
least with Firefox):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='test.xsl'?>
...

(and then obviously you need a separate test.xsl file.)

  What exactly is the problem you are having?

  I don't know if it matters, but that test xsl file starts with:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" indent="no"
  doctype-public="-//W3C//DTD HTML 4.01//EN"
  doctype-system="http://www.w3.org/TR/REC-html40/strict.dtd"
 />
...

(if it makes any difference.)

-- 
                                                          - Warp


Post a reply to this message

From: Le Forgeron
Subject: Re: The trouble with XSLT
Date: 20 Feb 2012 16:10:11
Message: <4f42b6b3$1@news.povray.org>
Le 20/02/2012 18:43, Warp nous fit lire :
> (and then obviously you need a separate test.xsl file.)
> 
>   What exactly is the problem you are having?

I think I understand Invisible (ouch!):
Assume a file a.xml and another file showme_pretty.xsl

To have the browser display a.xml using showme_pretty.xsl, the a.xml
must contains the reference of showme_pretty.xsl;
There is no way to create a file a_in_pretty.xml that would
automatically combine a.xml & showme_pretty.xsl; a.xml must be copied
inside a_in_pretty.xml

Now imagine there is not ONE a.xml, but hundreds of them... Bummer!


Post a reply to this message

From: Invisible
Subject: Re: The trouble with XSLT
Date: 21 Feb 2012 04:11:31
Message: <4f435fc3$1@news.povray.org>
>> 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...
>
> That's merely a shell-script:
> 1. find the closing of the first<?xml tag
> 2. insert your xsl tokens
> 3. copy verbatim the remaining document
> 4.
> 5. Profit.

How the heck do you do that from a shell script?

...oh, wait. You probably meant a /real/ shell, not CMD.EXE, right?


Post a reply to this message

From: Invisible
Subject: Re: The trouble with XSLT
Date: 21 Feb 2012 04:16:55
Message: <4f436107$1@news.povray.org>
On 20/02/2012 05:43 PM, Warp wrote:
> Invisible<voi### [at] devnull>  wrote:
>> 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.
>
>    I don't understand. This in an XML file seems to work just fine (at
> least with Firefox):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type='text/xsl' href='test.xsl'?>
> ...
>
> (and then obviously you need a separate test.xsl file.)
>
>    What exactly is the problem you are having?

Sure, that works. But now suppose I have /more than one/ XSL file. In 
order to select which one I want applied, I have to actually edit the 
XML file.

I'd prefer to have the link between XML and XSL in a file external to 
the XML file - but apparently that is impossible. (Unless you use an 
external 3rd party XSL tool.)


Post a reply to this message

From: clipka
Subject: Re: The trouble with XSLT
Date: 21 Feb 2012 04:26:08
Message: <4f436330$1@news.povray.org>
Am 20.02.2012 17:58, schrieb Invisible:
> On 20/02/2012 04:21 PM, Invisible wrote:
>
>> (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...)
>
> Oh dear God...
>
> https://bugzilla.mozilla.org/show_bug.cgi?id=98168
>
> Short story: Using the xsl:text disable-output-escaping='yes' setting
> doesn't work. It's supposed to allow you to output arbitrary text, and
> it works with IE, but not with Firefox. And it appears they're trying to
> claim it's IE that's broken, not Firefox. >_<

Actually both are standards compliant:

"An XSLT processor will only be able to disable output escaping if it 
controls how the result tree is output. This may not always be the case. 
For example, the result tree may be used as the source tree for another 
XSLT transformation instead of being output. An XSLT processor is not 
required to support disabling output escaping. If an xsl:value-of or 
xsl:text specifies that output escaping should be disabled and the XSLT 
processor does not support this, the XSLT processor may signal an error; 
if it does not signal an error, it must recover by not disabling output 
escaping."

IE behaves as mandated for a combo of an XSLT processor and an HTML 
rendering engine.

Firefox behaves as expected (by the spec authors) for a combo of an XSLT 
processor and a DOM tree rendering engine.

The spec concludes that "Since disabling output escaping may not work 
with all XSLT processors and can result in XML that is not well-formed, 
it should be used only when there is no alternative."


Post a reply to this message

From: clipka
Subject: Re: The trouble with XSLT
Date: 21 Feb 2012 04:36:42
Message: <4f4365aa$1@news.povray.org>
Am 20.02.2012 17:21, schrieb Invisible:
> 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.

Why does this come as such a surprise to you?

Remember that the same thing is common practice for HTML and CSS as 
well: If you want the HTML to be rendered using a particular style 
sheet, you'll usually specify that in the HTML header.

I'm not sure whether all modern browsers support client-supplied CSS, 
but I wouldn't be surprised if there were still some out there that 
don't. For instance I have no idea how to choose a custom CSS in 
Firefox; you can disable all CSS, or choose which of multiple 
server-supplied CSS to use, but that seems to be about it.


Post a reply to this message

From: Invisible
Subject: Re: The trouble with XSLT
Date: 21 Feb 2012 05:09:34
Message: <4f436d5e$1@news.povray.org>
>> Oh dear God...
>>
>> https://bugzilla.mozilla.org/show_bug.cgi?id=98168
>>
>> Short story: Using the xsl:text disable-output-escaping='yes' setting
>> doesn't work. It's supposed to allow you to output arbitrary text, and
>> it works with IE, but not with Firefox. And it appears they're trying to
>> claim it's IE that's broken, not Firefox. >_<
>
> Actually both are standards compliant:

> The spec concludes that "Since disabling output escaping may not work
> with all XSLT processors and can result in XML that is not well-formed,
> it should be used only when there is no alternative."

Ah. So in fact, the W3C specification is broken, since /clearly/ a 
system should not be specified to suddenly produce completely incorrect 
output if an optional feature is not implemented.

*sigh*

Meanwhile, it looks like my only options are either to start memorising 
Unicode code points by ID, or to save my XSL file as UTF-8 and watch the 
encoding get screwed up every time I touch the file...

(Let's not even get into the question of why the standard character 
names /only/ work in HTML, and not all SGML file types...)


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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