ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
RE: [xsl] filtering on following-sibling axis
by Don Smith other posts by this author
Nov 20 2001 4:48PM messages near this date
Re: [xsl] filtering on following-sibling axis | Re: [xsl] filtering on following-sibling axis
Thanks to both Jeni and Dave. Works great.

Don

-----Original Message-----
From: Jeni Tennison [mailto:jeni@[...].com]
Sent: Tuesday, November 20, 2001 4:24 AM
To: Don Smith
Cc: XSLT
Subject: Re: [xsl] 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
Thread:
Don Smith
Jeni Tennison
Don Smith
David Carlisle

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved