473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Value of 'first parent with a value'?

Is there a way in XSLT to write this XSL:Value-of select statement (which
I've written in plain english):

value of the attribute of the first ascendent to have a value.

In otherwords, I have an element, and I want to get the parent attribute
that contains an actual value up the chain.

This might be the immediate parent's attribute, the grandparent's attribute
or the great grandparent's attribute (max of 3 levels).

Is there away to do this in the value-of statement, or do I need to call a
template with a series of choose statements?

-Darrel
Nov 12 '05 #1
4 2612
> Is there away to do this in the value-of statement, or do I need to call
a
template with a series of choose statements?


Well, this is what I ended up doing:

if test ../@atribute != ''
value of ../@attribute
/if
if test ../../@atribute != ''
value of ../../@attribute
/if
if test ../../../@atribute != ''
value of ../../../@attribute
/if

a bit wordy, but so is xslt. If there's a slicker way to do this, please
share ;o)

-Darrel
Nov 12 '05 #2
> Is there away to do this in the value-of statement, or do I need to call
a
template with a series of choose statements?


Well, this is what I ended up doing:

if test ../@atribute != ''
value of ../@attribute
/if
if test ../../@atribute != ''
value of ../../@attribute
/if
if test ../../../@atribute != ''
value of ../../../@attribute
/if

a bit wordy, but so is xslt. If there's a slicker way to do this, please
share ;o)

-Darrel
Nov 12 '05 #3
darrel wrote:
a bit wordy, but so is xslt.
Don't blame XSLT. And after all that's XPath, which is completely
differently colored horse :)
If there's a slicker way to do this, please
share ;o)


ancestor::*[@attribute!=''][1]/@attribute

It selects first ancestor element (in reverse document order as
ancestor:: is reverse axis), which has nonempty @attribute and then
selects that attribute.

Another approach (not so effective though as it involves sorting):

(ancestor::*/@attribute[.!=''])[last()]

It selects all nonempty @attribute on ancestor elements and then takes
last one in document order - the first one in reverse document order.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #4
darrel wrote:
a bit wordy, but so is xslt.
Don't blame XSLT. And after all that's XPath, which is completely
differently colored horse :)
If there's a slicker way to do this, please
share ;o)


ancestor::*[@attribute!=''][1]/@attribute

It selects first ancestor element (in reverse document order as
ancestor:: is reverse axis), which has nonempty @attribute and then
selects that attribute.

Another approach (not so effective though as it involves sorting):

(ancestor::*/@attribute[.!=''])[last()]

It selects all nonempty @attribute on ancestor elements and then takes
last one in document order - the first one in reverse document order.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: HolaGoogle | last post by:
Hi, Sorrryy to ask such basic question but i do need your help! Here's what i'm trying to do: In my parent form i'm calling a my Iframe form to get certain value, then depending on that value...
4
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a...
0
by: darrel | last post by:
Is there a way in XSLT to write this XSL:Value-of select statement (which I've written in plain english): value of the attribute of the first ascendent to have a value. In otherwords, I have...
1
by: Steve Bywaters | last post by:
I'm attempting to do a lookup, using a javascript-launched child window to enable the user to select a value, then return that value to the parent/launching window. Pictures... to demonstrate...
13
by: Jason Shohet | last post by:
I have an ascx control, and it needs a value called 'orgID' which the parent page will have. I want to avoid the parent page setting values in fields on the ascx control since this violates...
8
by: patrizio.trinchini | last post by:
Hi All, I'would like to write an XSL transformation that changes the value of the atribute of a given element according to the value of another atttribute of the same element. For instance,...
5
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
1
AaronL
by: AaronL | last post by:
Hello, First I would like to say thank you all for your help in the past. I am stumped again. I am creating an e-commerce system and I want to be able to upload images to the server and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.