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

RE: How to select an attribute on the current node or

Subject: RE: How to select an attribute on the current node or its anchestor
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Apr 2011 18:40:36 +1200
RE:  How to select an attribute on the current node or
XSL 1:

<xsl:value-of select="ancestor-or-self::*[@data != ''][1]/@data" />

In XSL 2 you can construct a sequence of data attribute values which would
allow you to get the max() or min() value - that's not your requirement but it
might be a useful extension of it:

<xsl:value-of select="(ancestor-or-self::*/@data[. != ''])[last()]" />

Cheers
T

-----Original Message-----
From: Philipp Kursawe [mailto:phil.kursawe@xxxxxxxxx]
Sent: Friday, 15 April 2011 6:06 p.m.
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  How to select an attribute on the current node or its
anchestor

Hello,

given the following xml:

<node data="foo">
  <text id="1" data="bar"/>
  <text id="2"/>
</node>

I would like to know the XPath expression to select @data which
results in "bar" for @id=1 and "foo" for @id=2.

The general idea is to search for the attribute in the anchestor if
the current node does not contain the attribute all the way up to the
root node.

Thanks for your help!

Phil

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.