我有这样的XML:
<video id="647599250">
<studio/>
<director/>
<actorRef>916503210</actorRef>
<title>National Geographic's Mysteries of Egypt</title>
<dvd>22</dvd>
<laserdisk/>
<laserdisk_stock/>
<genre>special</genre>
<rating>R</rating>
<runtime>110</runtime>
<user_rating>3</user_rating>
<summary>Experience the magnificence of Egypt like never before!</summary>
<details>Legendary actor and native Egyptian Omar Sharif and Kate Maberly join National Geographic's award-winning filmmakers to weave a fascinating story of a grandfather who enchants his granddaughter with tales of tombs and treasures. Travel back more than 4,000 years to a time when the Great Pyramids of Giza were built.</details>
<vhs>15</vhs>
<beta_stock>5</beta_stock>
<year>1999</year>
<vhs_stock>88</vhs_stock>
<dvd_stock>22</dvd_stock>
<beta>14</beta>
</video>
有很多电影标签。
我正在运行以下代码:
for $movie in result/videos//video
order by $movie/genre, $movie/user_rating descending
return $movie/title
产生:
<?xml version="1.0" encoding="UTF-8"?>
<title>Enemy of the State</title>
<title>Star Wars</title>
<title>The Fugitive</title>
<title>Clerks</title>
<title>Six Days Seven Nights</title>
<title>Doquissåpan, avsnitt 1</title>
<title>Doquissåpan, avsnitt 2</title>
<title>Doquissåpan, avsnitt 4</title>
<title>Contact</title>
<title>2001: A Space Odyssey</title>
<title>Pinocchio</title>
<title>MUPPET TREASURE ISLAND</title>
<title>Au Revoir Les Enfants</title>
<title>La Femme Nikita</title>
<title>Seven</title>
<title>The Fear</title>
<title>Yellow Submarine</title>
<title>Carmen</title>
<title>Everest</title>
<title>National Geographic's Mysteries of Egypt</title>
此序列已按流派排序,然后通过user_rating在流派内排序。我想知道是否还有为每个类型的电影创建某种标题,如:
<genre genre="action">
<title>Enemy of the State</title>
<title>Star Wars</title >
<title>The Fugitive</title>
</genre >
<genre genre="comedy">
<title>Clerks</title>
<title>Six Days Seven Nights</title>
</genre>
<genre genre="drama">
<title>Contact</title>
<title>2001: A Space Odyssey</title>
</genre>
<genre genre="family">
<title>Pinocchio</title>
<title>MUPPET TREASURE ISLAND</title>
</genre>
<genre genre="foreign">
<title>Au Revoir Les Enfants</title>
<title>La Femme Nikita</title>
</genre>
<genre genre="horror">
<title>Seven</title>
<title>The Fear</title>
</genre>
<genre genre="musical">
<title>Yellow Submarine</title>
<title>Carmen</title>
</genre>
<genre genre="special">
<title>Everest</title>
<title>National Geographic’s Mysteries of Egypt</title>
</genre>
<genre genre="documentary">
<title>Doquissåpan, avsnitt 1</title>
<title>Doquissåpan, avsnitt 2</title>
<title>Doquissåpan, avsnitt 4</title>
</genre>
答案 0 :(得分:2)
试试这个:
for $genre in distinct-values(result/videos/video/genre)
order by $genre
return
<genre genre="{ data($genre) }">
{
for $movie in result/videos/video[genre=$genre]
order by $movie/user_rating
return $movie/title
}
</genre>
此外,它可以写成:
@RequestMapping(value = "/searchmedia", method = RequestMethod.GET)
public String searchForm(HttpServletRequest request, Map<String, Object> map) {
// This is what I want to get to the JSP file
Iterable<MediaFile> mediaFiles = repository.findAll();
map.put("mediaFiles", mediaFiles);
return "search";
}