|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Output conditional on preceding nodes.
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








