RE: Last tango in Paris
Brought to you by:
bs_php,
nigelswinson
From: Dietrich A. <die...@ga...> - 2002-02-21 02:36:07
|
Nigel, is multiple predicates implemented? ie: //node-test[myPredicate1][myPredicate2] if it's not, it would explain the "too many brackets" error. Peter, assuming that you actually have a tango element that contains the attribute "place" with a value of "paris" *and* all the "paris" nodes contain the same immediate parent, then the original xpath expression is correct and should only return 1 node: //tango[@place="paris"][last()] But if you have "paris" nodes that have *different* parents, then you may receive multiple nodes, as each my be the last child of the respective context node. From the spec, section 2.5 Abbreviated Syntax: "para[last()] selects the last para child of the context node" - d. > -----Original Message----- > From: php...@li... > [mailto:php...@li...]On Behalf Of Nigel > Swinson > Sent: Wednesday, February 20, 2002 3:59 PM > To: php...@li... > Subject: Re: Last tango in Paris > > > > If I have a lot of tango nodes with a place attribute, and I want to find > the > > 5th tango in Paris, according to the Xpath definition, I should be able to > do: > > > > tango[@place="Paris"][5] > > > > similarly, if I want to find the last tango in Paris, I should be able to > do: > > > > tango[@place="Paris"][last()] > > > > However, I've tried numerous variations on this in the usecases testbench > and > > can't get it to work - it either finds nothing or tells me there's an > invalid > > number of brackets. I can find all the tangos in Paris, and the last > tango, > > but not the two together. Is this a bug, something not handled (yet?), or > is > > there some other notation I can use? (ok, I know I can fetch all the > tangos > > in Paris and then use PHP to get the last in the array.) > > I wonder if this is related to the fact that //*[last()] returns multiple > nodes instead of one? > > I tried: > > //employee[(@gender='m') and (position() = last())] > > against: > > company-structure.xml > > at: > > http://www.carrubbers.org/scripts/php/xpath/testBench/useCases/index.php > > And it returns: > > [0] => /company[1]/department[1]/employee[2] > [1] => /company[1]/department[2]/employee[2] > [2] => /company[1]/department[4]/employee[2] > [3] => /company[1]/department[5]/employee[2] > > Where: > > //employee[(@gender='m')] > > Returns: > > [0] => /company[1]/department[1]/employee[1] > [1] => /company[1]/department[1]/employee[2] > [2] => /company[1]/department[2]/employee[1] > [3] => /company[1]/department[2]/employee[2] > [4] => /company[1]/department[3]/employee[1] > [5] => /company[1]/department[4]/employee[1] > [6] => /company[1]/department[4]/employee[2] > [7] => /company[1]/department[5]/employee[1] > [8] => /company[1]/department[5]/employee[2] > > Is that any use?? > > Nigel > > =========================== > For the most recent version of Php.XPath, and an archive of this list visit: > http://www.sourceforge.net/projects/phpxpath > > > _______________________________________________ > Phpxpath-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpxpath-users > |