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