Jump to content

xquery distinct-values and group by won't work


garfield

Recommended Posts

Hi,I'm making a XQUERY that has to show the different genres of all the movies and their actors.What I'm getting is:

<genre name="Drama"><actors><actor>name1</actor></actors></genre><genre name="Drama"><actors><actor>name2</actor><actor>name3</actor></actors></genre>

and so on ...This should be the output:

<genre name="Drama"><actors><actor>name1</actor><actor>name2</actor><actor>name3</actor></actors></genre><genre name="Thriller"><actors><actor>name4</actor><actor>name2</actor><actor>name5</actor></actors></genre>

An actor can be in the genre drama as well as thriller ... (name2 for example)The problem that occures is that my xquery shows all the genres and all the actors without a distinct-values or a group byThis is a xml example called OUT.XML:

<?xml version="1.0" encoding="UTF-8"?><holding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\ProjectDB\UIT2.xsd">	<cinemacom id="1">		<name>'t cinemake</naam>		<address>Lalalaan 69</address>		<postalcode>1000</postalcode>		<state>Brussels</state>		<amount_salespoints>12</amount_salespoints>		<tel_nr>02 222 22 22</tel_nr>		<room id="1">			<name>Dramaroom</naam>			<pres id="1">				<date>2007-10-29</date>				<time>14:15:00.0Z</time>				<movie id="1">					<name>Ben X</name>					<duration>93</duration>					<aantal_kopijen>2</aantal_kopijen>					<genre>Drama</genre>					<korte_inhoud>Ben is anders. Hij is licht autistisch. Zijn leven zit vol vreemde rituelen. Hij lijkt te leven in zijn eigen universum, dat zich voor meer dan de helft afspeelt in de wereld van online computergames. In de echte, harde wereld van een technische school is het leven voor hem een dagelijkse hel, met twee kerels die hem het leven bijna letterlijk onmogelijk maken. Ben heeft een plan. Een plan van één woord: moord! Dan komt zijn internetvriendin Scarlite in zijn leven. Dat behoorde niet tot het plan.</korte_inhoud>					<bespreking/>					<releaseDate>2007-09-26</releaseDate>					<maatschappij>MMG Film and TV Production</maatschappij>					<actors>						<actor>							<name>Greg Timmermans</name>						</actor>						<actor>							<name>Laura Verlinden</name>						</actor>						<actor>							<name>Marijke Pinoy</name>							<birthdate>1958-08-19</birthdate>						</actor>						<actor>							<name>Titus Devoogdt</name>						</actor>					</actors>					<directors>						<director>							<name>Nic Balthazar</name>							<birthdate>1964-07-24</birthdate>						</director>					</directors>					<nominations>						<reward>							<name>Grand Prix des Amériques</name>							<year>2007</year>						</reward>					</nominations>				</movie>			</pres>		</room>	</cinemacom></holding>

my xquery with group by that does not work:

for $movie in doc("OUT.xml")//holding//cinemacom//room//pres//moviegroup $movie as $moviegroup by $movie/genre as $genrereturn	<genre name="{ $genre }">		<actors>		{			for $actor in $moviegroup//actors//actor			return				<actor>{ $actor/name/text() }</actor>		}		</actors>	</genre>

How do I solve this problem?

Link to comment
Share on other sites

[...] my xquery with group by that does not work:
for $movie in doc("OUT.xml")//holding//cinemacom//room//pres//moviegroup $movie as $moviegroup by $movie/genre as $genrereturn	<genre name="{ $genre }">		<actors>		{			for $actor in $moviegroup//actors//actor			return				<actor>{ $actor/name/text() }</actor>		}		</actors>	</genre>

I haven't used XQuery all that much, but I didn't think it supported group by? Saxon doesn't think your XQuery is valid because of the word "group". Can you give a reference for this syntax?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...