Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Peter Flynn <pflynn@------>
To:
Date: 1/3/2006 4:10:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent