[xquery-talk] Need simple xquery help

David Carlisle davidc at nag.co.uk
Thu Dec 20 22:35:23 PST 2007


> The following query returns ALL the 'mfgs' - I don't understand why the
> "where" doesn't restrict it to only the Nelson entry.

$pngroup is the group you want but
$pmgroup/../../.. is the manufacture element so

$pmgroup/../../../mfg

selects all the mfg children of manufacture.

what you want is the mfg that's the gradparent of teh pmgroup select so
that's

$pmgroup/../..

Or more simply replace

for $pmgroup in
doc("file:example.xml")/pmcatalog/manufacture/mfg/pmdata/pmgroup
where contains($pmgroup/keyword, "pgroup8") 
return $pmgroup/../..

by

doc("file:example.xml")/pmcatalog/manufacture/mfg[contains(pmdata/pmgroup/keyword,"pgroup8")]



> But how does one retrieve only the node "header" (for lack of a term to use)
> - without its subsequent children.  Picking and choosing nodes with their
> attributes without the children.

The children of a node are an intrinsic property of the node (as is its
parent) if you just want an element node with the same name, but without
the children and parent of the node in the source then you need to
construct a new node, as you observed.

David


More information about the talk mailing list