[XML4Lib] XPath: Selecting nodes grouped with parent?

Binkley, Peter Peter.Binkley at ualberta.ca
Tue Oct 31 17:32:49 EST 2006


I haven't tried it, but how about
//database[type='Bibliography']/ancestor-or-self::* ? That should give
you the desired database elements plus all their ancestors but none of
their siblings. 

Peter

Peter Binkley
Digital Initiatives Technology Librarian
Information Technology Services
4-30 Cameron Library
University of Alberta Libraries
Edmonton, Alberta
Canada T6G 2J8
Phone: (780) 492-3743
Fax: (780) 492-9243
e-mail: peter.binkley at ualberta.ca



-----Original Message-----
From: xml4lib-bounces at webjunction.org
[mailto:xml4lib-bounces at webjunction.org] On Behalf Of Walker, David
Sent: Tuesday, October 31, 2006 2:41 PM
To: xml4lib at webjunction.org
Subject: [XML4Lib] XPath: Selecting nodes grouped with parent?

Hi all,
 
I have a simple set of XML files that include category and database
information for various library subscription databases.  Each category
has one or more subcategories, and each subcategory has one or more
databases, as such:
 
<category>
  <subcategory>
    <database />
    <database />
  </subcategory>
  <subcategory>
    <database />
    <database />
  </subcategory>
</category>
 
What I want to be able to do is apply a limit to the file based on one
or more attributes in the databases.  For example, only showing those
databases that have a <type> field with a value of 'Bibliography'. But I
want to be able to keep them in their subcategory groupings.  In
essence, I want to select both children (databases) and parent
(subcategory) nodes using an XPath expression with conditional logic
based on the children.
 
Is this possible?  I have a feeling the parent::axis might be able help
here, but I'm not sure.
 
 
I've tried a couple of things. This returns ONLY those databases that
have a type of Bibliography, but obviously doesn't include the
subcategory parent nodes:
 
  //database[type = 'Biography']
 
This returns subcategory nodes that have a child database with the type
of Bibliography, but it also includes ALL of the child nodes, regardless
of whether they have a type of 'Bibliography' or not.
 
  //subcategory[database/type = 'Biography']
 
 
I'm looking to find the intersection of those two, grabing any
subcategory node with a child database type of Bibliography, but then
limit the children to also be only ones with a type of Bibliogrtaphy.
 
I can tackle this in other ways, but was hoping a single Xpath
expresison could do the trick.  Thanks!
 
--Dave
 
 
-------------------
David Walker
Library Web Services Manager
California State University
http://xerxes.calstate.edu
_______________________________________________
XML4Lib mailing list
XML4Lib at webjunction.org
http://lists.webjunction.org/mailman/listinfo/xml4lib


More information about the XML4Lib mailing list