[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Output conditional on preceding nodes.

Subject: RE: Output conditional on preceding nodes.
From: Jeremiah Brown <jbrown@xxxxxxxxxx>
Date: Thu, 29 Nov 2001 13:03:45 -0500
jeremiah brown
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.