*Very* basic XML/XSL question...

T

Tom

Hey all,

I've been planning to get myself started with DocBook for quite some
time now, so when I unexpectedly encountered a task for which DocBook
might actually be very useful, I thought I'd no longer wait.

Some Googling pointed me to several beginner tutorials, and I chose to
get myself going with the guide at

http://rzserv2.fhnon.de/~lg002556/docbuch/

However, as soon as I hit the very first example, my enthusiasm quickly
faded away, since I can't get it to work properly, "as advertised", so
to say. The tutorial is in German, but that doesn't matter: at 1.2, the
reader is shown a really basic xml file, referring to some docbook.xls
file for it's styling. A screenshot shows what the result should look
like in a browser.

The author puts this in his xml file

<?xml-stylesheet type="text/xsl"
href="file://C:/x/docbookxsl/docbook-xsl-1.55.0/xhtml/docbook.xsl" ?>

I don't run Windows, so on my machine, the path to that xsl file
is /usr/share/xml/docbook/stylesheet/nwalsh/xthml/docbook.xsl. I've
tried every possible way to link to it from the xml file (file:///,
just /usr/..., climbing up the tree like ../../../....., in the end I
even put the whole docbook tree next to the file), but nothing works
(and yes, the file is readable by regular users). All I get is plain
tags. I fiddled around with the mimetype too (text/xml, text/xsl,
application/xml, application/xml+xsl) and tried serving it with apache,
all too no avail. On IRC, some kind people pointed me to some more
general, i.e. not specificly DocBook-related tutorials, which I
definitely plan to go through.

But still, I was wondering if I've got this straight: the data one
describes using XML, dictated by a DocBook DTD, should be *styled* by
an xsl file, right? Why, then, doesn't the above example, used in a
DocBook tutorial from someone who seems to know a lot about it, seem to
work? Wouldn't it be obvious what purposes a file called "docbook.xsl",
inside a directory called "xhtml", that is somewhere in a tree
underneath "stylesheets", could possible serve?

I'm a little confused, and since no-one on IRC could give me any direct
clue about it, I'm hoping the question is not *that* superfluous. I
apologize sincerely if it was.

Greets,
Tom
 
M

Matt

This example was probably intended to be run under MS Internet
Explorer. The xml-stylesheet directive tells the parser that this XML
doc should be transformed using the XSL doc indicated (note that XSL
transforms one XML document into a different XML document - it doesn't
simply 'style' it. In this case, it is probably transforming plain
XML into docbook format). If you are running the XML through a parser
that doesn't recognise the xml-stylesheet directive, they you won't
get the transformation. I suggest that you do the transformation
manually for each example. There are tons of tools around that will
allow you to do it from the command line.
 
T

Tom

[Sunday 29 February 2004 23:50] Matt in comp.text.xml:
This example was probably intended to be run under MS Internet
Explorer. The xml-stylesheet directive tells the parser that this XML
doc should be transformed using the XSL doc indicated (note that XSL
transforms one XML document into a different XML document - it doesn't
simply 'style' it. In this case, it is probably transforming plain
XML into docbook format).

Hey hey... I think you managed to make it clear to me what I was trying
to do and why it didn't work.

Let me get this straight: the XML document one writes, using a DocBook
DTD, can be transformed to any kind of output document by means of
specific XSL documents, designed for the purpose? But what, then, is
"DocBook"? Just a bunch of predescribed tags, that can be used to
efficiently write documentation of many kinds?
If you are running the XML through a parser
that doesn't recognise the xml-stylesheet directive, they you won't
get the transformation. I suggest that you do the transformation
manually for each example. There are tons of tools around that will
allow you to do it from the command line.

Yes, thanks.

Still, I wonder: why, then, did the example obviously work in Internet
Explorer, and not in Mozilla, Konqueror, or whatever browser I tried?
Is that determined by some browser-specific XML parser, which, in the
case of IE, managed to interpret the stylesheet on the fly?

Greets, and many thanks,
Tom
 
P

Patrick TJ McPhee

% specific XSL documents, designed for the purpose? But what, then, is
% "DocBook"? Just a bunch of predescribed tags, that can be used to
% efficiently write documentation of many kinds?

Not `Just a bunch', but `A bunch'.

% Still, I wonder: why, then, did the example obviously work in Internet
% Explorer, and not in Mozilla, Konqueror, or whatever browser I tried?

If it didn't work in Mozilla, it may be that the stylesheet doesn't
use the correct URL for the name space prefix. IE accepts two -- the
correct one, http://www.w3.org/1999/XSL/Transform, and another one
which only it accepts. There are many browsers out there, of which
only some can handle xslt.
 
M

Matt

XML directives (tags starting with <?) are not actually a part of the
XML document, but are instructions to the parser. In this case, the
instruction to the parser is to transform the document with the given
XSL doc. Directives rely on the parser recognising them, and off the
top of my head, I think the only directive that a parser MUST
recognise is <?xml ...?>. If a parser doesn't recognise a directive,
it just ignores it. I think (and may be wrong) that IE is the only
browser that supports the stylesheet directive.

I hope this makes things clearer for you.

Matt
 
A

Alain Frisch

Matt (comp.text.xml:60416):
XML directives (tags starting with <?) are not actually a part of the
XML document, but are instructions to the parser. In this case, the
instruction to the parser is to transform the document with the given
XSL doc. Directives rely on the parser recognising them, and off the
top of my head, I think the only directive that a parser MUST
recognise is <?xml ...?>. If a parser doesn't recognise a directive,
it just ignores it.

Well, not quite. The XML spec does not specify at all what parsers
should return, only what they accept. Some parsers may return processing
instructions.

Now, you also have document models, such as XPath's. And as a matter of
fact, processing instructions *are* part of this document model (so you'd
better use a parser that returns processing instructions to
"load" this document model...). Btw, the same applies to comments: it's
possible to write an XSLT stylesheet whose result depends on the content
of some comment in the input document. XML is a wonderful world ;-)
 
P

Patrick TJ McPhee

% XML directives (tags starting with <?) are not actually a part of the
% XML document, but are instructions to the parser.

OK, but Mozilla understands the xsl-stylesheet PI, so, in the absence of
more accurate information, we are free to speculate on the reasons
Mozilla might not be transforming the document -- one possible reason
would be a stylesheet which doesn't use the correct name space
declaration. A useful, informative, follow-up to my posting would have
told us the declaration that IE accepts but no other XSLT processor
does. Perhaps we'll have one of those tomorrow.
 
D

Derek Harmon

Patrick TJ McPhee said:
OK, but Mozilla understands the xsl-stylesheet PI,

It's the xml-stylesheet PI, and it's been a W3C Recommendation
for close to five years,

http://www.w3.org/TR/xml-stylesheet/

although IE and Mozilla are the only two browsers I know of that
have any sort of implementation for this.
A useful, informative, follow-up to my posting would have
told us the declaration that IE accepts but no other XSLT processor
does.

You don't mean,

http://www.w3.org/TR/WD-xsl

do you? There's nothing Microsoft-specific about it; it was just the old
XSL namespace URI when it was still a Working Draft. MSXML accepts
it for compatibility with legacy stylesheets that do not require XSLT 1.0
conformance.


Derek Harmon
 
P

Patrick TJ McPhee

% % > OK, but Mozilla understands the xsl-stylesheet PI,
%
% It's the xml-stylesheet PI, and it's been a W3C Recommendation
% for close to five years,

Oops -- sorry. wrt to browser support, there's nothing wrong with not
understanding any PI at all, but when you're diagnosing a problem, you
need to know whether the tools you use do understand the PIs you're
using.

% You don't mean,
%
% http://www.w3.org/TR/WD-xsl
%
% do you? There's nothing Microsoft-specific about it; it was just the old
% XSL namespace URI when it was still a Working Draft. MSXML accepts

I didn't say it was Microsoft-specific. I said that only IE accepts it.
I guess we could expand it to include any browser or other tool that
uses MSXML. The question here is why something works in IE, but not in
other browsers. The most obvious reasons are that the other browsers
don't provide xslt (but we know Mozilla does), and that IE accepts a
stylesheet name space declaration that other XSLT processors don't.

To the OP, if you have something like

<xsl:stylesheet xmlns:xsl='http://www.w3.org/TR/WD-xsl' ...>

then change it to

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' ...>

and you may find it works with Mozilla, and any other browsers that
support XSLT, as well as IE.
 
T

Tom

[Tuesday 02 March 2004 17:51] Patrick TJ McPhee in comp.text.xml:

<snip>

A little late, but thanks to all. I'm still trying to get the big
picture, but I'm sure I'll get the hang of it. Eventually. :)

Greets,
Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top