[xsl] position() problem

Subject: [xsl] position() problem
From: Maik Stührenberg <maik.stuehrenberg@xxxxxxxxxxxxxxxx>
Date: Tue, 11 Jul 2006 15:14:46 +0200
Hello list,

I have a problem with position(). I know that its value is the position
of the context node. I need a way to get a position of a
following-sibling node and want to compute its distance form the context
node.
Here's an example:

<sentence id="w441">
<token text="Schlie_lich" pos="N" id="w442">Schlie_lich</token>
<token text="werden" pos="V" id="w443">werden</token>
<token text="in" pos="PREP" id="w444">in</token>
<token text="Punkt" pos="N" id="w445">Punkt</token>
<token text="4" pos="NUM" id="w446">4</token>
<token text="einzelne" pos="A" id="w447">einzelne</token>
<token text="lexikalische" pos="A" id="w448">lexikalische</token>
<token text="," id="w449">,</token>
<token text="syntaktische" pos="A" id="w450">syntaktische</token>
<token text="und" pos="CC" id="w451">und</token>
<token text="prosodische" pos="A" id="w452">prosodische</token>
<token text="Mittel" pos="N" id="w453">Mittel</token>
<token text="genannt" pos="V" id="w454">genannt</token>
<token text="," id="w455">,</token>
<token text="die" pos="PRON" id="w456">die</token>
<token text="zu" pos="PREP" id="w457">zu</token>
<token text="r" pos="DET" id="w458">r</token>
<token text="Bestimmung" pos="N" id="w459">Bestimmung</token>
<token text="der" pos="DET" id="w460">der</token>
<token text="jeweiligen" pos="A" id="w461">jeweiligen</token>
<token text="Lesart" pos="N" id="w462">Lesart</token>
<token text="beitragen" pos="V" id="w463">beitragen</token>
<token text="." id="w464">.</token>
</sentence>

What I want is to select all token elements with the attribute/value
pair pos='N'. Having selected a token/@pos='N' I'd like to select its
following sibling token/@pos='N' if and only if it is in a specified
distance (e.g., 5 tokens away).
If both tokens are in the specified distance all tokens should be
displayed (starting from N1 up to N2 with all other tokens between them).

I've tried several different attempts but didn't managed to get the
value of the position of the current node (N1) and its following sibling
node to check if they are in the right distance. So all I have is a
template which displays all tokens (the special ones in bold).

Any help would be appreciated.

Thanks in advance,

Maik St|hrenberg

...
<xsl:template match="sentence">
<p>
 <b>
  <xsl:text>sentence: </xsl:text>
  <xsl:value-of select="@id" />
 </b>
 <br />
 <xsl:choose>
  <xsl:when test="count(token[@pos='N'])>1">
   <xsl:for-each select="token">
    <xsl:choose>
     <xsl:when test="@pos='N'">
      <b>
       <xsl:value-of select="@text" />
       <span style="font-size: x-small">
       <xsl:text> (</xsl:text>
       <xsl:value-of select="@id" />
       <xsl:text>) [</xsl:text>
       <xsl:value-of select="position()" />
       <xsl:text>] </xsl:text>
       </span>
      </b>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="@text" />
      <span style="font-size: x-small">
      <xsl:text> (</xsl:text>
      <xsl:value-of select="@id" />
      <xsl:text>) [</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text>] </xsl:text>
      </span>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:for-each>
  </xsl:when>
  <xsl:otherwise>
   <xsl:text>only one token with pos='N'</xsl:text>
  </xsl:otherwise>
 </xsl:choose>
</p>
</xsl:template>
...

Current Thread