[XML4Lib] XPath: Selecting nodes grouped with parent?
Walker, David
dwalker at calstate.edu
Tue Oct 31 16:40:35 EST 2006
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
More information about the XML4Lib
mailing list