【发布时间】:2020-02-10 19:58:29
【问题描述】:
我有一个 XML 文件。我想从重复值中检索最大值节点(在下面的例子中,author、title 和genre 字段相同,但number 字段不同)。
<?xml version="1.0"?>
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<number>1234</number>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<number>1235</number>
</book>
<book>
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<number>1236</number>
</book>
<book>
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<number>1237</number>
</book>
<book>
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<number>1238</number>
</book>
<book>
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<number>1239</number>
</book>
<book>
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<number>1240</number>
</book>
<book>
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<number>1246</number>
</book>
<book>
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<number>1247</number>
</book>
<book>
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<number>1248</number>
</book>
<book>
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<number>1241</number>
</book>
<book>
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<number>1242</number>
</book>
<book>
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<number>1243</number>
</book>
<book>
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<number>1244</number>
</book>
<book>
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<number>1245</number>
</book>
</catalog>
这是预期的输出:
<?xml version="1.0"?>
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<number>1234</number>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<number>1235</number>
</book>
<book>
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<number>1236</number>
</book>
<book>
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<number>1237</number>
</book>
<book>
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<number>1238</number>
</book>
<book>
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<number>1239</number>
</book>
<book>
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<number>1248</number>
</book>
<book>
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<number>1241</number>
</book>
<book>
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<number>1242</number>
</book>
<book>
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<number>1243</number>
</book>
<book>
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<number>1244</number>
</book>
<book>
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<number>1245</number>
</book>
</catalog>
作者在哪里Thurman, Paula。应检索最大数量的节点。有什么方法可以检索输出吗?如果是这样,请指导我正确的方向。
提前致谢!!
【问题讨论】:
标签: xml xquery xquery-3.0