Newbie Frustration:

Larry Lindstrom

Usenet Archive
Joined
Sep 4, 2003
Messages
50
Reaction score
0
Hello Again:

I appreciate all the assistance I've received
from this group. But I'm having trouble getting
traction in my effort to understand XML.

I took some time to research this, and I tried
to figure it out, but I'm stuck on the very next
lesson in ZVON's XSLT tutorial:

http://www.zvon.org/xxl/XSLTutorial/Output/example6_ch1.html

XML Source, I added the two PI statements:

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

<source>

<bold>Hello, world.</bold>
<red>I am </red>
<italic>fine.</italic>

</source>

XSL:

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

<xsl:template match="bold">
<p>
<b>
<xsl:value-of select="."/>
</b>
</p>
</xsl:template>

<xsl:template match="red">
<p style="color:red">
<xsl:value-of select="."/>
</p>
</xsl:template>

<xsl:template match="italic">
<p>
<i>
<xsl:value-of select="."/>
</i>
</p>
</xsl:template>

</xsl:stylesheet>

Internet Explorer does fine. The appropriate
bold, red and italic words are printed.

Mozilla displays nothing, blank screen.

Ok, I'll try to make this work. Suggestions
from this group that have helped with the last
examples:

Set the output method by adding one of the
following to the XSL:

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

Nothing, blank page with either one of
these.

Wrap <html> tags around the contents of the
xsl:stylesheet element:

Mozilla displays a gray screen and ignores
the right mouse button. No hint as to
the problem.

Wrap <html> tags around the contents
of the templates:

Blank screen

Comment out all but one template, leave the
<html> tags in the template.

That works! Well it works if I only want
one template.

Why don't I get more than one template in the
contents my xsl:stylesheet element? The
stylesheet is the root element, isn't it? So I
should be able to have any number of xsl:template
elements inside the stylesheet element, shouldn't
I?

When I comment out all but one template, for
example the "bold" template, why did that match?

The xml had a "/source/bold" element, how did
XSTL find "bold"? The ZVON xpath tutorial shows
"//bold" to be the syntax to find any element with
that name in the hierarchy.

I'm in serious need of some tools. Preferably
free, to display the output of the XSLT, and to
report on the correctness of the XML and XSL files.
What do you recommend?

I tried W3C's validator on both the xml and the
xsl, and was told both files need a DOCTYPE. I
don't see exactly what to enter for a DOCTYPE in
an XML or XSL file, but when I try to cut and paste
examples of DOCTYPE from W3C's "Choosing a DOCTYPE"
page, nothing good happens.

Is there a tutorial with examples that work with
Mozilla? Is the problem with tutorials depending on
Microsoft proprietary features, Mozilla's failure to
meet W3C standards, or me being an idiot?

I'm a C++ programmer, why am I having so much
trouble connecting to XML?

Thanks
Larry
 

Thomas Scheffler

Usenet Archive
Joined
Sep 17, 2003
Messages
16
Reaction score
0
Larry said:
Hello Again:

I appreciate all the assistance I've received
from this group. But I'm having trouble getting
traction in my effort to understand XML.

I took some time to research this, and I tried
to figure it out, but I'm stuck on the very next
lesson in ZVON's XSLT tutorial:

http://www.zvon.org/xxl/XSLTutorial/Output/example6_ch1.html

XML Source, I added the two PI statements:

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

<source>

<bold>Hello, world.</bold>
<red>I am </red>
<italic>fine.</italic>

</source>

XSL:

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

<xsl:template match="bold">
<p>
<b>
<xsl:value-of select="."/>
</b>
</p>
</xsl:template>

<xsl:template match="red">
<p style="color:red">
<xsl:value-of select="."/>
</p>
</xsl:template>

<xsl:template match="italic">
<p>
<i>
<xsl:value-of select="."/>
</i>
</p>
</xsl:template>

</xsl:stylesheet>

Internet Explorer does fine. The appropriate
bold, red and italic words are printed.

Internet Explorer displays it because it's not strict standard conform.
Mozilla displays nothing, blank screen.

Mozilla is looking for your root element template. You always need to define a template for your root element, ex:

<xsl:template match="/">
<html>
....
<xsl:apply-templates/>
</html>
</xsl:templates>

This should do the trick...

I'm in serious need of some tools. Preferably
free, to display the output of the XSLT, and to
report on the correctness of the XML and XSL files.
What do you recommend?

I'm using a servlet and tomcat for that issue but of cause there will be a lot of more easier things to do that, but I don't know of one.
I tried W3C's validator on both the xml and the
xsl, and was told both files need a DOCTYPE. I
don't see exactly what to enter for a DOCTYPE in
an XML or XSL file, but when I try to cut and paste
examples of DOCTYPE from W3C's "Choosing a DOCTYPE"
page, nothing good happens.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MyRootElement SYSTEM "MyDTDFileForSyntaxChecking.dtd">

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

As you see you don't really need a DocType for XML or XSL but you can define one for your xml-documents.
Is there a tutorial with examples that work with
Mozilla? Is the problem with tutorials depending on
Microsoft proprietary features, Mozilla's failure to
meet W3C standards, or me being an idiot?

Maybe it's all of them but I can't help you with a tutorial specific to mozilla since it should be standart complient. So only your current one seems to be untested with standart xslt and standard mozilla...
I'm a C++ programmer, why am I having so much
trouble connecting to XML?

So do I with C/C++
Thanks
Larry

Greets

Thomas Scheffler
 

Colin Webber

Usenet Archive
Joined
Sep 16, 2003
Messages
2
Reaction score
0
Personally, I gave up developing straight XSLT and wrote a simple presentation mechanism which generates the XSLT for me using the static HTML!

"Xorro" is an opensource presentation framework for web applications that facilitates two-way iterative development between programmers and web designers. It provides the power of XSLT in a simpler, more maintainable form.

- Read a description:
http://sourceforge.net/docman/display_doc.php?docid=17067&group_id=81250

- Download the latest version with a XHTML --> XSLT --> HTML demo:
http://prdownloads.sourceforge.net/xorro/xorro_with_demo.zip?download

View a highly successful web project that uses Xorro:
http://www.t-refer.com
https://www.t-refer.com/core/proces...ATHAWTE-2&enrollment.enrollment-type=new-sgc2

Enjoy!

Cheers
Colin
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% I appreciate all the assistance I've received
% from this group. But I'm having trouble getting
% traction in my effort to understand XML.

Actually, you seem to be having trouble understanding HTML.

[...]

% XML Source, I added the two PI statements:

% <?xml version="1.0" encoding="ISO-8859-1"?>
% <?xml-stylesheet type="text/xsl" href="page_03_01.xsl"?> % % <source> % % <bold>Hello, world.</bold> % <red>I am </red> % <italic>fine.</italic> % % </source>

This is fine.

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

First problem is that you're generating HTML, but you're not specifying the HTML output tag. This is fine if you want to generate XHTML, except that you need to be even more careful about creating a file with the correct structure in place if you're generating XHTML, but isn't guaranteed to work if you're trying for HTML.

[...]

% Internet Explorer does fine. The appropriate
% bold, red and italic words are printed.

Traditional approach to handling HTML is to forge ahead and do your best regardless of whether you have valid HTML. The problem is that it encourages people to generate, or at least doesn't discourage people from generating, invalid HTML, and ultimately this limits what you can do in terms of adding new functionality. Joe Clark's _Building Accessible Web Sites_ has a reasonable explanation of why it's evil and pointless to do this.

% Mozilla displays nothing, blank screen.

On the other hand, it's not helpful for a browser to just give a blank screen rather than explaining that there's a problem, so no points to either side.

Look at the output of your transformation:

<p><b>Hello, world.</b></p>
<p style="color:red">I am </p>
<p><i>fine.</i></p>

The minimal requirement for SGML or XML mark-up is that the document be wrapped in a single element, which in the case of HTML is <html>. You need the transformation to give you this:

<html>
<p><b>Hello, world.</b></p>
<p style="color:red">I am </p>
<p><i>fine.</i></p>
</html>

Or this

<?xml version="1.0" encoding="iso-8859-1"?>
<html>
<body>
<p><b>Hello, world.</b></p>
<p style="color:red">I am </p>
<p><i>fine.</i></p>
</body>
</html>

The secret is to figure out what to do to your stylesheet to get the results that you need. You seem to be applying wild shots in the dark in the hopes that you can get it to work.

% Wrap <html> tags around the contents of the
% xsl:stylesheet element:

Well, all this will do is stop it from being a stylesheet. What you need is to add <html> tags around the output, not the input.

% Wrap <html> tags around the contents
% of the templates:

Do you mean

<xsl:template match="bold">
<html>
<p>
<b>
<xsl:value-of select="."/>
</b>
</p>
</html>
</xsl:template>

?

What this will do is create this output:

<html><p><b>Hello, world.</b></p></html>
<html><p style="color:red">I am </p></html>
<html><p><i>fine.</i></p></html>

Which is still not valid html.

% Comment out all but one template, leave the
% <html> tags in the template.
%
% That works! Well it works if I only want
% one template.

Because it gives, say,

<html><p><b>Hello, world.</b></p></html>

which is valid HTML.

% Why don't I get more than one template in the
% contents my xsl:stylesheet element? The
% stylesheet is the root element, isn't it? So I
% should be able to have any number of xsl:template
% elements inside the stylesheet element, shouldn't
% I?

Your stylesheet is structurally fine, it's just the output that's no good.

% The xml had a "/source/bold" element, how did
% XSTL find "bold"? The ZVON xpath tutorial shows
% "//bold" to be the syntax to find any element with
% that name in the hierarchy.

I don't know if the tutorial is bad or if you've skipped over something important. XPath path expressions consist of a sequence of steps, each of which specifies a search axis, a node test, and one or more predicates. Each step is evaluated in the contexts of a set of nodes provided by the step to its left. //bold is a short-hand for /descendent-or-self:node/child:bold, where / at the start says that the initial step should be evaluated in the context of the root node, descendent-or-self and child are search axes, node and bold are node tests, and there are no predicates in sight.

Having said all that, match expressions aren't full XPath expressions, and they get evaluated against every node in the tree, more-or-less.

% I'm in serious need of some tools. Preferably
% free, to display the output of the XSLT, and to
% report on the correctness of the XML and XSL files.
% What do you recommend?

You could get libxml and libxslt (http://xmlsoft.org) or Xerces and Xalan (http://www.apache.org). There are several others floating around the net.

% I tried W3C's validator on both the xml and the
% xsl, and was told both files need a DOCTYPE.

You should read the first bit of the XML spec where the difference between valid and well-formed XML is discussed.

% I'm a C++ programmer, why am I having so much
% trouble connecting to XML?

It seems like you haven't read any basic introductory material and you're not really trying to understand what's going on, just to get something that works. Once you get past this, it will help with XSLT if you keep in mind that it's more like m4 than C++.
 

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
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top