Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2015, 06:20 PM
Authorized User
 
Join Date: Mar 2012
Posts: 25
Thanks: 9
Thanked 0 Times in 0 Posts
Default Selecting descendant with specific name and attribute

I want to select all descendant nodes of "first" nodes that are "third" nodes and which attribute name is equal "this"

I'm trying to do that by using the XPath

root/first/descendant::node()[name()='third' and current()/@name='this']

but it does not appear to work.

In other words I would like to select the node "<third name="this"/>" in the tree below (the tree is just an example, I do not know in advance what nodes are nested in "first" nodes)

Code:
<root>
<first name="1">
<second1 name="a">
<third name="this"/>
</second1> <second2 name="b"/> <second1 name="c"/>
</first>
<first name="2">
<second3 name="d"/> <second4 name="e"/> <second1 name="f"/>
</first>
</root>
Thanks for your help, and excuse me if the question sounds silly :)
 
Old February 21st, 2015, 08:34 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

current() gives you the context from outside the predicate - in this instance probably the document root, so current()/@name will never exist.

Just [name()='third' and @name='this'] should work fine I think.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 21st, 2015, 10:58 AM
Authorized User
 
Join Date: Mar 2012
Posts: 25
Thanks: 9
Thanked 0 Times in 0 Posts
Default

You are right! It was indeed a silly question with a very simple solution that I couldn't see myself :)

Thanks a lot!
 
Old February 25th, 2015, 05:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Instead of testing whether the node is named 'third' why not just search for:
Code:
root/first/descendant::third[@name = 'this']
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Added attribute to specific element tron_thomas XSLT 3 September 7th, 2010 11:59 AM
How to find attribute for specific element? QuadFather XML 1 April 7th, 2010 12:41 PM
Finding if an attribute has a specific value mphare XSLT 1 February 2nd, 2009 06:57 PM
sort on specific attribute kgoldvas XSLT 2 July 17th, 2007 09:42 AM
Selecting unique value of an attribute and render vinaura XSLT 4 December 18th, 2006 04:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.