xsl-list
[Top] [All Lists]

Re: [xsl] Pure XPath Question

2011-07-24 12:41:07
Philip Vallone wrote:

I have a xpath expression that searches a xml file for the word 'faa'. Using 
pure xpath 1.0, I want to be able to search each section element that has the 
word 'faa' in the name attribute. I want to return the @name of the ancestor 
chapter/@name for each section.

This expression only returns a count of 1

/data/volume/chapter/section/@name[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
 'faa')]/ancestor::chapter/@name

while this returns a count of 2.

/data/volume/chapter/section/@name[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
 'faa')]

I understand why I am not getting the desired result, but not sure how to get 
it.

Desired result:

Chapter 1. Handbook Organization, Use, and Revision
Chapter 1. Handbook Organization, Use, and Revision

Is this possible with using a single xpath expression?

I don't think so, XPath 1.0 gives you a set of nodes where duplicates are eliminated so you don't get the result you want, namely a list with the same "name" attribute node of the same "chapter" element contained twice.


--

        Martin Honnen --- MVP Data Platform Development
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>