RE: [xsl] position() test for processing boundaries

Subject: RE: [xsl] position() test for processing boundaries
From: Ron Van den Branden <ron.vandenbranden@xxxxxxxx>
Date: Tue, 23 Nov 2004 12:08:50 +0100
Hi Michael and Wendell,

Thanks for your quick and helpful reactions! They guided me in the right direction toward a practical solution. Since I found one, I'll happily try to explain and share it.

Just for reference purposes, I'll copy the example element hierarchy:

<p>
 <q n="1>
   <app n="2">
     <rdg n="3">rdg1</rdg>
     <rdg n="4">rdg2</rdg>
     <rdg n="5">rdg3</rdg>
   </app>
   [text]
   <anchor n="6"/>
   <app n="7">
     <rdg n="8">rdg1</rdg>
     <rdg n="9">rdg2</rdg>
     <rdg n="10">rdg3</rdg>
   </app>
 </q>
 [text]
 <app n="11">
   <rdg n="12">rdg1</rdg>
   <rdg n="13">rdg2</rdg>
 </app>
 <anchor n="14"/>
 <q n="15">
   <app n="16">
     <rdg n="17">rdg1</rdg>
     <rdg n="18">rdg2</rdg>
     <rdg n="19">rdg3</rdg>
   </app>
   [text]
   <anchor n="20"/>
   text
   <app n="21" TEIform="app">
     <rdg n="22">rdg1</rdg>
     <rdg n="23">rdg2</rdg>
   </app>
   [text]
   </q>
</p>

I used the general <xsl:copy-of select="(.//*)[position() &gt; 3]"/> instruction just for testing what went wrong with the <xsl:apply-templates select="(.//*)[position() &lt; 6]/descendant-or-self::app"/> instruction in the stylesheet I'm developing. (I want to limit further processing of <app> elements by specifying start and end context position boundaries, in this case the first <anchor n="6"/> element.)

On first consideration I thought it was an unexpected effect of the position() test causing the unwanted processing of

   <app n="2">
     <rdg n="3">rdg1</rdg>
     <rdg n="4">rdg2</rdg>
     <rdg n="5">rdg3</rdg>
   </app>
   <app n="7">
     <rdg n="8">rdg1</rdg>
     <rdg n="9">rdg2</rdg>
     <rdg n="10">rdg3</rdg>
   </app>

...instead of limiting it to just the <app n="2"> element. Closer inspection however showed that it rather was its combination with the "descendant-or-self::app" XPath step. This seemed too broad in (correctly, of course) selecting not just the <app> elements before the end context position, but also *all* descendant <app>s of all elements occurring before that position (explaining the inclusion of the <app n="7"> element).

Your explications were illuminating enough for me to correctly identify my misunderstanding, and narrowing down the XPath step to "self::app". The instruction <xsl:apply-templates select="(.//*)[position() &lt; 6]/self::app"/> finally does what I expect it to, selecting only the <app n="2"> element. And now I even know why (:-))

Thanks,

Ron

--
Ron Van den Branden
Wetenschappelijk attachi
Centrum voor Teksteditie en Bronnenstudie (CTB)
Koninklijke Academie voor Nederlandse Taal- en Letterkunde (KANTL)
Koningstraat 18 / b-9000 Gent / Belgium
e-mail : ron.vandenbranden@xxxxxxxx
http://www.kantl.be/ctb/staff/ron.htm

Current Thread