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="//*[(_at_)*[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(_at_)CraneSoftwrights(_dot_)com
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