473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2643
> 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
41207
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 enable or disable my submit button in my parent form without using any refresh/reload or submit button in my form. Looks realy simple but i don't know how to get it work. actualy, i've been able to populate listbox,text boxes in my parent with...
4
22210
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 description and a class_id (stored in the value attribute of each option). The user will then select a class from the drop-down list. What I want to do is have a control in the parent browser window which can store the class_id and the...
0
316
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 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).
1
2410
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 the issue: http://users.bigpond.net.au/stevebywaters/image1.gif shows the first window. The operator can press the 'Select' button (to get a value to put into 'Location' entry field). When they do, a child window is launched, showing a list of...
13
378
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 encapsulation principles, SO... I want to know if InvokeMember can be used to return a value from the parent. ie: Type myParent = this.Page.GetType(); string strOrgid = myParent.InvokeMember("GetOrgID", System.Reflection... null, this.Page, new...
8
1886
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, given the following XML file: <?xml version="1.0" encoding="UTF-8"?> <sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
3231
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 at conventions. I have a main form with two subforms. On the main form, there is a text box that displays the sum of total orders entered in the subform, . I'm trying to create another text box on the main form, that looks at the subtotal...
0
2046
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. Ok my problem is the following. I have a class that contains a "MakeByteArray" function. I have many objects of that class. Inside that function, I have a private variable, that is NOT static. It seems that when I put all these objects in...
1
4247
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 assign them to products. For the product ID, I have an auto increment value for the primary key to avoid duplicate item numbers. Since I do not want to pass all of my record values to my image upload program (when I write it), I assume to just submit...
0
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.