|
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
Section']/following-sibling::p[2]"/>
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"/>
</xsl:variable>
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">
<xsl:apply-templates>
</xsl:if>
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: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Output conditional on pre, David Carlisle | Thread | RE: [xsl] Output conditional on pre, Delany Nick |
| [xsl] document.write, anna . stefani | Date | Re: [xsl] Sorting in descending ord, Jörg Heinicke |
| Month |