[XML4Lib] XPath: Selecting nodes grouped with parent?
Conal Tuohy
Conal.Tuohy at vuw.ac.nz
Tue Oct 31 17:16:10 EST 2006
David Walker wrote:
> 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
When you say "apply a limit to the file" what does this mean in
practice? i.e. is this expression used in an XSLT which should show only
a subset of nodes in the input? or in an XQuery? What context is the
XPath expression supposed to work in?
> 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.
> 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']
This expression does return only the subcategory nodes, and does not
include their child nodes.
However, if you were to use the expression in XSLT like so:
<xsl:copy-of select="//subcategory[database/type = 'Biography']"/>
... then you would indeed get all the descendant nodes, but this is an
artifact of xsl:copy-of, not of the XPath expression itself.
More information about the XML4Lib
mailing list