This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: quick [but difficult] Xpath Question
- From: Wendell Piez <wapiez at mulberrytech dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 23 Aug 2002 16:34:43 -0400
- Subject: Re: [xsl] Re: quick [but difficult] Xpath Question
- Reply-to: xsl-list at lists dot mulberrytech dot com
Juan,
Try (//XX)[1]
And hope that your processor is optimized to stop after it gets the first
one rather than traversing the entire tree.
NB, this is not the same as //XX[1], which translates as
/descendant-or-self::node()/child::XX[1]
where the predicate operates only on the second step (the child step), so
you get all XX elements that are the first XX child of their parents -- not
what you want.
Grouping it as
(/descendant-or-self::node()/child::XX)[1]
(or using the abbreviated form as above), solves that particular problem.
If you have namespace-qualified elements around and you want any namespace
but local-name 'XX' you'll have to do
(//*[local-name()='XX'])[1]
Good luck,
Wendell
At 04:17 PM 8/23/2002, you wrote:
Hello:
I need an XPath statement which will return the first node found in the
document, where the element's local-name() = 'XX'. The node can be anywhere
in the source tree. I've tried all sorts of different statements but they
either result too many records [ I just need the fist "hit"] or no records
at all.
I only need the first node, not all the nodes. and the name of the element
is only known at runtime. This Xpath will be inside an XSLT file which acts
as a "find command", displaying the first node found in the document.
Thanks in advance
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list