Re: [xsl] Restricting the scope of preceding:: and following::

Subject: Re: [xsl] Restricting the scope of preceding:: and following::
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Tue, 03 Jan 2006 17:24:35 +0100
(taken from http://www.zvon.org/xxl/XSLTreference/Output/axis_following.html)

>>>
Axis: following::

Standard excerpt:
the following axis contains all nodes in the same document as the context node that are after the context node in document order, excluding any descendants and excluding attribute nodes and namespace nodes
<<<


Note the part "excluding any descendants"!

Perhaps you are looking something is the line of:
(descendant::*|following-sibling::*|ancestor::*[count(ancestor::s|$sentence) = 1]/following-sibling::*/descendant::*)/@type


HTH,
Geert

Peter Flynn wrote:

I seem to have missed a trick here (probably due to festive indulgence).

A user has a small corpus of densely-marked TEI text (newspaper articles) identifying each sentence, clause, and phrase (and some
specific words as well). Phrase markup can contain further phr,
cl, and w subelements nested to arbitrary depth.


In sentences with a noun phrase <phr ana='NPS'> followed (at some
distance) by a verb phrase <phr ana='VP'> there will be some
intervening phr, cl, and w elements bearing a type= attribute
which she needs to examine (type is not used on any other elements).

If these were all at the same depth, a combination of following-
sibling:: and preceding-sibling:: could identify them. But as they
may be at any depth, their only common factor (apart from lying between the two NPS and VP <phr> elements mentioned above) is that they will by definition be descendants of the same <s> ancestor as
those two elements.


Using preceding:: and following:: to locate the required elements
between the two <phr> elements, and set a variable to hold the ancestor <s> element node, I should be able to use the identity
enumeration test to restrict selection to those phr, cl, and w
elements which are within the same sentence, eg


<!-- pick out every sentence containing a noun phrase, a
verb phrase, and some elements with a type attribute -->
<xsl;for-each select="//s[descendant::phr[@ana='NPS']]
[descendant::phr[@ana='VP']]
[descendant::*[@type]]">
<!-- memorise the identity of this sentence -->
<xsl:variable name="sentence" select="."/>
<!-- process the relevant noun phrase elements -->
<xsl:for-each select="descendant::phr[@ana='NPS']">
<!-- process each element with a type attribute which follows the noun phrase but restrict it to
those which are part of the current sentence -->
<xsl:for-each select="following::*[@type]
[count(ancestor::s|$sentence)=1]">
...


However, if I trace the behaviour by outputting the name and type
attribute of all elements recursed by this innermost loop, I find
it is pulling into the loop scope *all* following::*[@type] elements throughout the rest of the document every time, and ignoring the test for membership of the current sentence.


I've clearly made a simple and careless mistake here but I can't
see the wood for the trees.

Wish List: a following-member:: axis which would locate elements
after the current context element in document order, at any depth (sibling or below), but never going outside the tree defined by the parent of the current context :-)


Happy new year, for those whose year is new.

///Peter



-- Drs. G.P.H. Josten Consultant



Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl


De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.


Current Thread