Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Complicated Querry [Thread Next] Re: Complicated QuerryTo: NULL Date: 4/2/2007 10:16:00 AM On Apr 1, 11:11 pm, "Dimitre Novatchev" <dimit...@tpg.com.au> wrote: > "Bhavin" <v2desper...@gmail.com> wrote in message > > news:1175477394.982261.297980@e...... > > > > >I had querry that " Display the Games 'India' won." > > > XML File: > > > <?xml version="1.0"?> > > <playoffs> > > <team id="ID0"> > > <name>India</name> > > </team> > > <team id="ID1"> > > <name>Brazil</name> > > </team> > > <team id="ID2"> > > <name>ManU</name> > > </team> > > <team id="ID3"> > > <name>France</name> > > </team> > > > <player id="101" team-id="ID0" dob="1985-01-01" role="GoalKeeper"> > > <name>John Smith</name> > > </player> > > <player id="102" team-id="ID0" dob="1984-02-02" role="Attack"> > > <name>Sachin Tendulkar</name> > > </player> > > <player id="103" team-id="ID0" dob="1983-03-03" role="Defense"> > > <name>Bryan</name> > > </player> > > > <player id="201" team-id="ID1" dob="1985-04-04" role="GoalKeeper"> > > <name>Imran Khan</name> > > </player> > > <player id="202" team-id="ID1" dob="1985-05-05" role="Attack"> > > <name>David</name> > > </player> > > <player id="203" team-id="ID1" dob="1984-12-12" role="Defense"> > > <name>Ronaldo</name> > > </player> > > > <player id="a1" team-id="ID2" dob="1983-01-01" role="GoalKeeper"> > > <name>Rivaldo</name> > > </player> > > <player id="a2" team-id="ID2" dob="1982-01-01" role="Attack"> > > <name>Ronaldinho</name> > > </player> > > <player id="a3" team-id="ID2" dob="1985-01-01" role="Attack"> > > <name>Cafu</name> > > </player> > > > <player id="b1" team-id="ID3" dob="1980-07-07" role="GoalKeeper"> > > <name>Beckham</name> > > </player> > > <player id="b2" team-id="ID3" dob="1981-08-08" role="Attack"> > > <name>Carlos</name> > > </player> > > <player id="b3" team-id="ID3" dob="1983-09-0" role="Attack"> > > <name>Starwarko</name> > > </player> > > > <game team1-id="ID0" team2-id="ID1"> > > <goal player-id="101"/> > > <goal player-id="101"/> > > <goal player-id="201"/> > > <card player-id="101" color="yellow"/> > > <card player-id="101" color="yellow"/> > > </game> > > <game team1-id="ID0" team2-id="ID1"> > > <goal player-id="101"/> > > <goal player-id="202"/> > > <goal player-id="201"/> > > <card player-id="101" color="yellow"/> > > <card player-id="101" color="yellow"/> > > </game> > > <game team1-id="ID2" team2-id="ID3"> > > <goal player-id="a1"/> > > <goal player-id="a2"/> > > <goal player-id="b1"/> > > <card player-id="b2" color="yellow"/> > > <card player-id="a3" color="yellow"/> > > </game> > > </playoffs> > > > What i did is first find the > > > 1] DISPLAY ALL THE GAMES WHICH India PLAYED > > > /playoffs/game[@team1-id | @team2-id =/playoffs/team[name="India"]/ > > @id] > > > 2] DISPLAY ALL THE PLAYER OF THE TEAM india WITH PLAYER ID > > > /playoffs/player[@team-id =/playoffs/team[name="India"]/@id]/@id > > > 3] DISPLAY ALL THE GOALS made in the matches in which india played > > > //game[@team1-id | @team2-id =//team[name="India"]/@id]//goal/@player- > > id > > > 4] combine 2 result to find goal made by India. > > > /playoffs/game[@team1-id | @team2-id =/playoffs/team[name="Legia"]/ > > @id]/goal[@player-id = > > /playoffs/player[@team-id =/playoffs/team[name="Legia"]/@id]/@id] > > > I dont know how to proced ahead to compare.....etc > > if u can help ....... that would be appreciated > > Using the XPath Visualizer one can quickly arrive at the following: > > variable Expression > ================================================================= > $vGameswithIndia /*/game[/*/team[name='India']/@id = @*] > > $vIndianPlayers /*/player[@team-id = /*/team[name = > 'India']/@id] > > $vIndianPlayerIds /*/player[@team-id = /*/team[name = > 'India']/@id]/@id > > Then, the following XPath 1.0 expression selects all games in which India > won (scored more goals than the opposite team): > > $vGameswithIndia[count(goal[@player-id = $vIndianPlayerIds]) > > count(goal[not(@player-id=$vIndianPlayerIds)])] > > The XPath Visualizer highlights the one game selected by this XPath > expression: > > <game team1-id="ID0" team2-id="ID1"> > <goal player-id="101"/> > <goal player-id="101"/> > <goal player-id="201"/> > <card player-id="101" color="yellow"/> > <card player-id="101" color="yellow"/> > </game> > > We can easily replace the variable references in the above XPath expression > and thus get the following XPath expression, which produces the wanted > result: > > /*/game > [/*/team[name='India']/@id > = > @*] > [count(goal[@player-id = /*/player[@team-id = /*/team[name = > 'India']/@id]/@id]) > > > count(goal[not(@player-id=/*/player[@team-id = /*/team[name = > 'India']/@id]/@id)]) > ] > > We can even read and understand this XPath expression quite well: > > Select all games in which one of the teams was India > > (and) such that > the count of goals scored by a player of the team of India > > was greater than > > the count of goals scored by players not from the team of India. > > Hope this helped. > > Cheers, > Dimitre Novatchev Thank you for helping me out, i spent almost 1 day in solving that Query. I really appreciate your work | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
