Re: [xsl] Newbie: HTML output ordering problem.

Subject: Re: [xsl] Newbie: HTML output ordering problem.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 18 Aug 2003 15:37:24 -0400
Matt,

An unofficial XSL FAQ is at: http://www.dpawson.co.uk/xsl/index.html. There is a wealth of information there.

Of particular interest to you may be the bit Dave has clipped from a post by Clark Evans on "Push vs. Pull" processing. This is relevant since the problems you are experiencing are due to your trying to "pull" your data with your stylesheet, rather than let the processor "push" it for you. (Because, for example, you are selecting "section" and "para" nodes explicitly, you are re-ordering them, whereas if you selected them together they would remain in the order in which they appear in the source.)

While it can be tough to find until you know what to look for, there is a huge amount of coverage of these basic issues available on line and in some excellent books on XSLT. Doing some research into the XSLT processing model, which (your code indicates) you haven't yet come to terms with, would be time very well spent.

Fix your error wrt the ordering of sections and paras (BTW your "section" is badly named, since it's just a - flat - header, not a section) by changing the instructions:

        <xsl:apply-templates select="article/section" />
        <xsl:apply-templates select="article/para"/>

to just <xsl:apply-templates select="article/section | article/para"/>


Doing that research on the processing model should demonstrate to you why this is so.

Cheers,
Wendell

At 02:28 PM 8/18/2003, you wrote:
Hello all.

I've run into a problem with the ordering of my output. I've tried looking for an answer, but I
can't find one in the archives or via Google, so I'm turning to you for help. If this is a
FAQ/RTM question, please let me know where the FAQ list/Manual are as I can't seem to
find them.


The project is to take an article for an ezine and transform it into HTML (and PDF
eventually). I've got the XML for the articles created, and I'm working with the XSL file
now. The problem I have is that when I run the XSL file as it is below through Xalan-J, I get
an output file that has a list of headers followed by a list of paragraphs. What I'm looking to
get is an intermingled list of headers and paragraphs.


Thanks for your help!

ARTICLE.XML
<?xml version="1.0" ?>
<article>
<title>This would hold the title of the article.</title>
<summary>This is a one sentance summary of the article.</summary>
<author email="someone@xxxxxxxxxxxxx"
homepage="http://somewhere.com/author";>John Doe</author>
<aboutAuthor>Biographical information goes in here.</aboutAuthor>
<section>Introduction</section>
<para sectionTitle="Introduction">put some text here. put some text here. put
some text here. put some text here. </para>
<para>
<link destination="Slashdot.org" name="slashdot" />
<link destination="http://www.cnn.com"; name="CNN" />
<link destination="http://www.mozilla.org/"; name="Mozilla" />
</para>
<section>Installation</section>
<para> put some text here. put some text here. put some text here. put some
text here. </para>
<para>abcdefghijklmnopqrstuvwxyz. abcdefghijklmnopqrstuvwxyz.
abcdefghijklmnopqrstuvwxyz. abcdefghijklmnopqrstuvwxyz. </para>
<section>Using the program</section>
<para>put some text here. put some text here. put some text here. put some text
here. </para>
<para><warning>Do Not feed the Lions!</warning> <emphasis>put some text
here.</emphasis> put some <emphasis>text</emphasis> here. put some text here.
</para>
<para>abcdefghijklmnopqrstuvwxyz. <link destination="http://slashdot.org";
name="slashdot" /> abcdefghijklmnopqrstuvwxyz. abcdefghijklmnopqrstuvwxyz.
abcdefghijklmnopqrstuvwxyz. </para>
<para> <keyboardInput>ftp ftp.mozilla.org</keyboardInput></para>
<para>in the <objectName>System Setup</objectName> folder, select the
<objectName>Mouse</objectName> object and go to the Comet Cursor page. Make sure
the <dialogOption>Comet Cursor On</dialogOption> option has a checkmark in the box.
Now you have to restart your computer, you can do this by pressing the
<keys>Control-Alt-Delete</keys> combination.</para>
<section>Summary</section>
<para>put some text here. put some text here. put some text here. put some text
here. </para>
</article>


TRANSFORM.XSL
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0
Transitional//EN"/>

<xsl:template match="/">
<html>
<head><title>VOICE Newsletter - Date <xsl:value-of select="article/title"
/></title></head>
<body>
<div id="header">
<h1><xsl:value-of select="article/title" /></h1>
<p class="authorname">by <a><xsl:attribute
name="href">mailto:DESPAM-<xsl:value-of select="article/author/@email"
/></xsl:attribute><xsl:value-of select="article/author" /></a></p><!--need to insert
HREF="" into <A> tag for mailto to function.-->
<p><xsl:value-of select="article/summary" /></p></div>
<div id="mainContent">
<xsl:apply-templates select="article/section" />
<xsl:apply-templates select="article/para"/>


                <div id="references">
                <h2>References and Links</h2>
                <ul>
                        <xsl:apply-templates select="article/para/link"/>
                </ul>
                </div><!--end references-->

        </div><!--end main content-->
                <div id="authorInfo"><p><strong><xsl:value-of
select="article/author"/>'s</strong>&#160;&#160;<xsl:value-of
select="article/aboutAuthor"/></p></div>
        </body>
        </html>
</xsl:template>

<!-- ====================== -->
<xsl:template name="section">
<h2>
<xsl:value-of select="." />
</h2>
</xsl:template>

<!-- ====================== -->
<xsl:template match="article/para">
<p><xsl:value-of select="."/></p><!--templates for links, images, emphasis,
etc. launched from this template?-->
</xsl:template>


<!-- ====================== -->
<xsl:template match="article/para/link">
<li><a><xsl:attribute name="href"><xsl:value-of
select="./@destination"/></xsl:attribute><xsl:value-of select="./@name"/></a></li>
</xsl:template>


</xsl:transform>


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread