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

Re: accessing specific elements

Subject: Re: accessing specific elements
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 8 May 2001 09:14:45 +0100
get specific xsl value
Hi Sabine,

> -     count the tokens which have a domlex[@attribute='location']
>         (this is no problem, I just use
> count(//domlex[@attribute='location'])"/>))
>
> -     access only those tokens with an [@attribute='location'],  so that
> I can express
>         the condition: "If the first element with  @attribute='location'
> and the third have the same
>         value, then write out only one as the origin (and the middle one
> as the destination).
>
> I thought of storing the value of the first in a variable and
> comparing it with subsequent ones... but I can't get it work...

You can store them in a variable like:

<xsl:variable name="locs"
  select="/input_stream/chunk/token/domlex[@attribute = 'location']" />

(I step down from the root rather than using the descendant axis as
it's likely to be more efficient - you might want to check the path to
make sure it's right for your source XML.)

The $locs variable now contains three nodes - the three domlex
elements with the @attribute attribute equal to 'location'.  When you
index into a node set like this, then their positions (as indicated in
positional predicates like [1]) are relative to the other nodes in the
node set.  So you can get the first with $locs[1], the second with
$locs[2] and the third with $locs[3].

So you should be able to use the following to get the kind of output
that you're after.

   Origin: <xsl:value-of select="$locs[1]/@value" />
   <xsl:choose>
      <xsl:when test="$locs[1]/@value = $locs[3]/@value">
         Destination: <xsl:value-of select="$locs[2]/@value" />
      </xsl:when>
      <xsl:otherwise>
         Via: <xsl:value-of select="$locs[2]/@value" />
         Destination: <xsl:value-of select="$locs[3]/@value" />
      </xsl:otherwise>
   </xsl:choose>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.