[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: [xsl] Restricting the scope of preceding:: and following::
From: Peter Flynn <pflynn@xxxxxx>
Date: Tue, 03 Jan 2006 16:10:12 +0000

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


Current Thread
Keywords
tei