Re: my nearest sibling

Subject: Re: my nearest sibling
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 06 Jul 1999 09:07:01 -0700
At 99/07/06 16:41 +0000, you wrote:
>Any volunteers to express "go up and get my nearest older sibling"?

In the April specification, the preceding axis (ordered in proximity order
(1 is closest), not document order (1 is first in parse order)) will find
the older sibling:

   from-preceding-siblings(*[1])

or explicitly if you know you only have one label:

   from-preceding-siblings(label)

... but this isn't yet implemented in XT.

>In this example:
>
> <list type="gloss"><label><gi>front</gi></label><item>contains any
> prefatory matter (headers, title page, prefaces, dedications, etc.)
> found before the start of a text proper.</item>
>
>when processing <item>, I want to get my paws on the associated
><label>.

Until the preceding access is implemented, I would use the element's index
as in my example below.

>actually, position() never seems to do what I expect. does it
>produce the sibling count?

It produces the context node's position amongst the nodes of the context
node list ... which varies depending on what you are doing (which is
probably why you've had problems understanding what exactly it is doing).
In my example below, I'm explicitly setting the context node list to the
children of <list> and then relying on that in my calculations with
position().

I hope this helps.

............ Ken


T:\FTEMP>type test.xml
<?xml version="1.0"?>
<list type="gloss"><label><gi>front</gi></label><item>contains any
prefatory matter (headers, title page, prefaces, dedications, etc.)
found before the start of a text proper.</item></list>

T:\FTEMP>type test.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>

<xsl:template match="/">                    <!--root rule-->
    <xsl:apply-templates/>
</xsl:template>                          

<xsl:template match="list">                 <!--document element-->
    <xsl:apply-templates/> <!--set node list to children-->
</xsl:template>                          

<xsl:template match="label"/> <!--postpone processing-->

<xsl:template match="item"> <!--node list = siblings-->
  <xsl:variable name="this-pos" expr="position()"/> <!--sibling #-->
Label = <xsl:value-of select="../*[$this-pos - 1]"/> <!--prev sibling-->
</xsl:template>

</xsl:stylesheet>

T:\FTEMP>call xsl test.xml test.xsl test.txt
T:\FTEMP>type test.txt
Label = front
T:\FTEMP>


--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Publications:   Introduction to XSLT (3rd Edition) ISBN 1-894049-00-4
Next instructor-led training:   MS'99 1999-08-16  MT'99 1999-12-05/06


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread