RE: [xsl] Output conditional on preceding nodes.

Subject: RE: [xsl] Output conditional on preceding nodes.
From: Jeremiah Brown <jbrown@xxxxxxxxxx>
Date: Thu, 29 Nov 2001 13:03:45 -0500
> select="h1[.='foo']/following-sibling::p[3]"

> <xsl:apply-templates select="h1[.='Best

This is the preferred way: select only the nodes you want to operate on,
when you apply the template.

But, if you find yourself in a situation where you must select a bunch of
nodes, and then process some of them differently based on where they fall in
the list, a sequence number may be helpful.

For instance, inside a template applied to ALL of your headers and
paragraphs in document order:

  <xsl:variable name="seq-num">
    <xsl:number level="single" count="p" from="h1"/>

Here seq-num will evaluate to the index of the paragraph since the last
(most recent) header in the list. Then,

<xsl:if test="name()='p' and $seq-num=2">

will print out ONLY the second paragragh under each header.

If you want to print out a different paragraph depending on the header text,
change the pattern in the 'from' attribute to be header-specific, such as

from="h1[text()='Best Section']"

and provide a case for each header.

Once again, this is hacking your way out of a situation that is best avoided
by applying templates more selectively, if possible.

 XSL-List info and archive:

Current Thread