[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Creating Forward/Backward HTML links from multi-file XSL processing

Subject: Re: [xsl] Creating Forward/Backward HTML links from multi-file XSL processing
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 24 Jan 2004 14:34:08 -0500

At 2004-01-24 10:11 -0700, Randolph Kahle wrote:
I am using XSL to translate a set of XML documents into a corresponding set of HTML documents. I am stuck trying to figure out how to create <a > ... </a> links in HTML that display forward and backward pointers through the web pages.
Each topic has the following (partial) structure:


<!-- Used to link topics together -->
<course>Course Name</course>
I would prefer to keep the meta information about topic sequence out of each topic file.

Basically, as I understand it, I need to point backward one sibling topic and forward one sibling topic and detect the end cases where there is no forward/backward sibling.

You will still need a unique identifier for each topic, so I'll assume you'll move the <file> element one level higher to be a child of <topic>.

When you are in the template rule for a topic, you can test just as you asked in prose:

  <xsl:if test="preceding-sibling::topic">
    <a href="{preceding-sibling::topic[1]/file}.htm">
      <xsl:value-of select="preceding-sibling::topic[1]/title"/>

... and the mirror using following-sibling:: axis for the next. Note that the [1] predicate (when in a step) addresses the closest in that direction, because the axes are proximity ordered.

I hope this helps.

.............................. Ken

p.s. when I do this with my course presentation slides, I use an ID-typed attribute for the base of the filename since that guarantees uniqueness across the XML document; if you inadvertently name two topics with the same file, you will get overwrite without getting any errors; but if you add an ID-typed attribute to topic and you validate the document, the validation process will flag duplicates before you start creating any files.

Alternatively, you could use a key table:

<xsl:key name="files" match="topic/file" use="."/>

... then when you go to produce each of the actual files:

  <xsl:if test="count(key('files',file))>1">
     <xsl:message terminate="yes">Duplicate filename!</xsl:message>

-- Public courses: sign up for one or both soon to reserve your seat! Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22 Hong Kong, China: 2004-05-17 Bremen, Germany: 2004-05-24 World-wide on-site corporate, government & user group XML training

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc

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

Current Thread