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

RE: filtering on following-sibling axis

Subject: RE: filtering on following-sibling axis
From: "Don Smith" <donalds@xxxxxxxxxx>
Date: Tue, 20 Nov 2001 10:48:01 -0600
following sibling axis predicate
Thanks to both Jeni and Dave. Works great.

Don

-----Original Message-----
From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Sent: Tuesday, November 20, 2001 4:24 AM
To: Don Smith
Cc: XSLT
Subject: Re:  filtering on following-sibling axis


Hi Don,

> from the context of <section type="subsection"> I need to access all
> the following sibling sections up to the next <section
> type="subsection">. Of course I can get them all with the expression
> 'following-sibling::section', and exclude the following sections
> that have the attribute type="subsection" by adding the predicate
> [not(@type='subsection')], but I'm unable to write a filter that
> stops accessing the following siblings at the next subsection.

You can look at it this way: you want to get all the following section
elements whose type is not 'subsection' and whose closest preceding
section with a type of 'subsection' is the current section. This won't
be true for any section elements after the following 'subsection'
because *their* closest preceding 'subsection' will be the next one.

To put that in an XPath: all the following section elements:

  following-sibling::section

whose type is not 'subsection':

  following-sibling::section[@type != 'subsection']

and whose closest preceding section with a type of 'subsection':

  following-sibling::section[@type != 'subsection']
    [... preceding-sibling::section[@type = 'subsection'][1] ...]

is the same as the current section:

  following-sibling::section[@type != 'subsection']
    [generate-id(preceding-sibling::section[@type = 'subsection'][1])
     = generate-id(current())]

If you have several headings in your book, you might need to expand
the interesting preceding siblings to headings as well:

  following-sibling::section[@type != 'subsection']
    [generate-id(preceding-sibling::section
                   [@type = 'subsection' or @type = 'heading'][1])
     = generate-id(current())]

I'd usually put this in a key, so that you associate each subsection
generated ID with its sections:

<xsl:key name="sections"
   match="section[@type != 'subsection' and @type != 'heading']"
   use="generate-id(preceding-sibling::section
                      [@type = 'section' or @type = 'heading'][1])" />

Then you could just do:

  key('sections', generate-id())

to get all the relevant following sections.
     
I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.