[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: my nearest sibling

Subject: Re: my nearest sibling
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 06 Jul 1999 09:07:01 -0700
from preceding siblings
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.