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

Re: XPath for variable search anywhere

Subject: Re: XPath for variable search anywhere
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Jan 2004 08:43:45 -0500
xpath select node anywhere
At 2004-01-22 12:48 +0000, Andrew Maclean wrote:
I have a variable in my XSL (call it myVar) and I wish to search the entire node hierarchy for nodes which share it's name.

Do you mean nodes whose name is the value of myVar? Or nodes that share the same name "m","y","V","a","r"? I'll assume the former.


<xsl:copy-of select="//$myVar">

You can use:


<xsl:copy-of select="//node()[name(.)=$myVar]"/>

... but this is *not* namespace safe.

If you only wanted to check elements:

<xsl:copy-of select="//*[name(.)=$myVar]"/>

... but same caveat about namespaces.

Perhaps if you give the context of why the node name is important in your search, another solution might be presented. The name() function is suitable for exposition but *not* suitable for node checking because it isn't namespace-safe.

causes my processor (4suite) to generate an XsltException. Does anybody know the syntax I need to look at all levels of the hierarchy for nodes that have the name (or attribute) "myVar"?

"have" the attribute myVar? or *is* the attribute myVar?


For "an element that has an attribute named by myVar" it would be:

<xsl:copy-of select="//*[@*[name(.)=$myVar]]"/>

For "an element or attribute named by myVar" it would be the top one above.

I hope one of these is what you need ... I'm sorry I couldn't understand precisely what you were looking for from your wording.

...................... Ken


-- Public courses: sign up for one or both soon to reserve your seat! Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22 Hong Kong, China: 2004-05-17 Bremen, Germany: 2004-05-24 World-wide on-site corporate, government & user group XML training

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


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.