xml editor

Supported platforms

Compatible with Windows7 & Mac OS X Snow Leopard

Ready for data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XPath 1.0 Question: Can two sibling nodes each select their parent node to yield two nodes?


Subject: Re: [xsl] XPath 1.0 Question: Can two sibling nodes each select their parent node to yield two nodes?
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Thu, 23 Sep 2010 09:21:43 +0530

Hi Roger,
    I think with XPath 1.0 the best we can do is, to get all instances
of "Book" elements as follows:

//book[author = 'Paul McCartney']

Then we iterate these 'book' elements and get value of 'genre' element
for them (by looking at the preceding-sibling::genre[1] for example).
Iteration with XSLT or an API is possible.

As others have noted, returning the full sequence as you have stated
is possible with XPath 2.0.

On Thu, Sep 23, 2010 at 2:38 AM, Costello, Roger L. <costello@xxxxxxxxx>
wrote:
> Hi Folks,
>
> This is an XPath 1.0 question.
>
> Consider this document:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <books>
> B  B <category>
> B  B  B  B <genre>Autobiography</genre>
> B  B  B  B <book>
> B  B  B  B  B  B <name>My Life and Times</name>
> B  B  B  B  B  B <author>Paul McCartney</author>
> B  B  B  B </book>
> B  B  B  B <book>
> B  B  B  B  B  B <name>The Beatles</name>
> B  B  B  B  B  B <author>Paul McCartney</author>
> B  B  B  B </book>
> B  B </category>
> B  B <category>
> B  B  B  B <genre>Music</genre>
> B  B  B  B <book>
> B  B  B  B  B  B <name>Eight Days a Week</name>
> B  B  B  B  B  B <author>Paul McCartney</author>
> B  B  B  B </book>
> B  B </category>
> </books>
>
> I would like to select the value of <genre> of each <book> with <author>
equal to 'Paul McCartney'. Thus, I want the XPath to yield:
>
> B  B Autobiography
> B  B Autobiography
> B  B Music
>
> I thought that either of these XPath expressions would do the job:
>
> B  B //book[author='Paul McCartney']/../genre
>
> B  B //book[author='Paul McCartney']/preceding-sibling::genre
>
> However, both result in this:
>
> B  B Autobiography
> B  B Music
>
> What XPath 1.0 expression will produce the desired result?
>
> /Roger



--
Regards,
Mukul Gandhi


Current Thread
Keywords
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>®XML Editor