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

XPath 1.0 Question: Can two sibling nodes each select

Subject: XPath 1.0 Question: Can two sibling nodes each select their parent node to yield two nodes?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Wed, 22 Sep 2010 17:08:54 -0400
 XPath 1.0 Question: Can two sibling nodes each select
Hi Folks,

This is an XPath 1.0 question.

Consider this document:

<?xml version="1.0" encoding="UTF-8"?>
<books>
    <category>
        <genre>Autobiography</genre>
        <book>
            <name>My Life and Times</name>
            <author>Paul McCartney</author>
        </book>
        <book>
            <name>The Beatles</name>
            <author>Paul McCartney</author>
        </book>
    </category>
    <category>
        <genre>Music</genre>
        <book>
            <name>Eight Days a Week</name>
            <author>Paul McCartney</author>
        </book>
    </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:

    Autobiography
    Autobiography
    Music

I thought that either of these XPath expressions would do the job:

    //book[author='Paul McCartney']/../genre

    //book[author='Paul McCartney']/preceding-sibling::genre

However, both result in this:

    Autobiography
    Music

What XPath 1.0 expression will produce the desired result?

/Roger

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-2011 All Rights Reserved.