Newbie Question - This One is Easy.

L

Larry Lindstrom

Hi Experts:

I've decided to go through ZVON.org's XSLT tutorial.

The first XSLT example is at:

www.zvon.org/xxl/XSLTutorial/Output/example1_ch1.html

Here is the XML, with a reference to the stylesheet
and other syntactic sugar added at the front:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="page_01_01.xsl"?>

<source>

<title>XSL</title>
<author>John Smith</author>

</source>

Here is the XSL, unchanged from the example:

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

<xsl:template match="/">
<h1>
<xsl:value-of select="//title"/>
</h1>
<h2>
<xsl:value-of select="//author"/>
</h2>
</xsl:template>

</xsl:stylesheet>

The transform to be performed is obvious, but I
decided to cut and paste it into my website so I
could watch it work.

The expected output is "XSL" in H1 font, followed
on the next line by "John Smith" in H2 font.

Mozilla 1.3 running on Solaris, displays this as
"XSLJohn Smith", on the first line, plain text, no
visible format or font processing.

Internet Explorer, running on Win 2000, displays
the XML as expected, with H1 and H2 fonts.

So, what am I doing wrong?

A couple of other questions, while I have your
attention:

I've looked at Mozilla's tools and haven't been
able to find anything that will display the XSLT
output, or the DOM for an XML page. Is there a
way to see these?

What do the question marks (<?...?>) in the first
lines of the XML file signify?

Thanks
Larry
 
P

Patrick TJ McPhee

[...]

% Here is the XSL, unchanged from the example:
%
% <xsl:stylesheet version = '1.0'
% xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
%
Try adding

<xsl:eek:utput method="html"/>

here. On reflection, since the default should be xml, which in this case
is close enough, the problem is likely that Mozilla is ignoring the
xml-stylesheet PI. Does it claim to support it?

[...]

% What do the question marks (<?...?>) in the first
% lines of the XML file signify?

<? and ?> delimit an XML processing instruction (PI). These are exactly
that: instructions to the XML processing software, telling it what to
do with the XML data. PIs starting with `xml' are supposed to have been
defined by the W3C and one might reasonably expect them to be portable
across all XML processing software. Other PIs are likely to be specific
to one program.
 
R

Richard Tobin

Larry Lindstrom said:
Here is the XML, with a reference to the stylesheet
and other syntactic sugar added at the front:

The output of this stylesheet is an XML document containing

<h1>XSL</h1><h2>John Smith</h2>

(not actually a well-formed document because it has two top-level
elements, but that's not really the problem).

Mozilla would display this the way you wanted if it believed it
was HTML or XHTML, but it has no reason to believe this.

You could do any of the following:

(a) set the XSL output method to HTML using <xsl:eek:utput method="xml"/>

(b) wrap an <html> element around the output, which would have the
side-effect of setting the output method to HTML

(c) put the <h1> and <h2> elements in the XHTML namespace (and
preferably wrap them with <html> and <body> elements, and add
a <head> element, to make it a valid XHTML document)

-- Richard
 
L

Larry Lindstrom

Patrick said:
[...]

% Here is the XSL, unchanged from the example:
%
% <xsl:stylesheet version = '1.0'
% xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
%
Try adding

<xsl:eek:utput method="html"/>

here. On reflection, since the default should be xml, which in this case
is close enough, the problem is likely that Mozilla is ignoring the
xml-stylesheet PI. Does it claim to support it?

Thanks Again Patrick:

Your suggestion works.

I don't know where to find claims of compatibility
from Mozilla.

Mozilla has properly displayed XML with other XSL
files, like the one you helped me with two days ago,
without that statement.

W3schools' XSL tutorial shows that xsl:stylesheet
is recognized by Netscape Navigator 6, which is kind
of the same as Mozilla. Isn't it?

Thanks
Larry
 
L

Larry Lindstrom

Richard said:
The output of this stylesheet is an XML document containing

<h1>XSL</h1><h2>John Smith</h2>

Thanks Richard:

Is there some way to display XSLT output, in
Mozilla or IE?
(not actually a well-formed document because it has two top-level
elements, but that's not really the problem).

Yea, I see that now. I was being lazy with
cutting and pasting, and I didn't notice that the
example was more a code fragment than a proper
XSL file.
Mozilla would display this the way you wanted if it believed it
was HTML or XHTML, but it has no reason to believe this.

You could do any of the following:

(a) set the XSL output method to HTML using <xsl:eek:utput method="xml"/>

Patrick suggested this, and it works. But I
know an XSL file is XML, and needs to comply with
XML's standards.
(b) wrap an <html> element around the output, which would have the
side-effect of setting the output method to HTML

This is what I chose to do, I wrapped the XSLT with
(c) put the <h1> and <h2> elements in the XHTML namespace (and
preferably wrap them with <html> and <body> elements, and add
a <head> element, to make it a valid XHTML document)

Namespaces are still a "Do it like the example
shows and don't worry" kind of thing. I don't
understand them.

Thanks
Larry
 
R

Richard Tobin

Larry Lindstrom said:
Thanks Richard:

Is there some way to display XSLT output, in
Mozilla or IE?

Sorry, don't know. I always run a standalone XSLT processor. But
that doesn't help you if you suspect that the browser is getting it
wrong.

-- Richard
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top