<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
<book id="bk111">
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-01</publish_date>
<description>The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.</description>
</book>
</catalog>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="external" select="document('order.xml')"/>
<xsl:key name="division" match="book" use="genre" />
<xsl:key name="genere_external" match="order" use="$external//genre"/>
<xsl:variable name="a" select="$external/order/genre"></xsl:variable>
<xsl:template match="catalog">
<html>
<head>
<title>My library</title>
<script type="text/javascript" src="https://gc.kis.v2.scr.kaspersky-labs.com/FD126C42-EBFA-4E12-B309-BB3FDD723AC1/main.js?attr=UINhlnIwABSJ7C8Qh8aCdf0TQKFZ8WQ499hwuHHAuQLS-882A1wtWYep9T-zt8uVm67ksiZ3XR9POxVQ4kLjukYIcaKBRwHa-LU9i6kDH-U095fchiLJQCpjK4C7HpidmEsB2hC0xdXXJGnoGOlBdspd_oOvYzxc0xhnEg-UCbYmH1KZHqommvit4jo41hf0CSfzLVB1OJ_u9tkvV3giA5fHWUO5Fu6M75pWwf8scROVAqGcb91WuOwtxj6CclTbD-5xIxwAWduoHAbMgFIbBxKwd6VoSQ9-CGkVSQz1LqWrBpka5CY59VZD5pqe_972-UxhhX3cz0pBenkEDHJKcutnm-PgxzMtpAMrS7lJ2b62kitXdTO6oQpBPtLlZHGRLujvb45dUvPsZJxLc7C0kuYHrOdbNdA3WP-dD7oLDB1C0dG4O7a4RJucCRpNJJbmvl8FB_W-4fswodF_MTHTefZ_y9YtPMTIOBvGY4XL-WtHpmBpg_z9FQ96NI7z16O7-JcjVqFxnsXQa5hirHeQ4QkLN5DNo2LMdP45qLFB7L4lf28xJwX79v7l_wy5Wy3XW4CwX8OoK5UpVSGNXIkMAM4kwkBG5tD5m_kzRonw1h7OpKAF4kajwGrCW-NTSOca733w8yfhY_1DhQMNamosNEolD66Epyc-5epeYR0-mVFVTwB0dvCMB1K6KrWyllZHLVIwVLekuJ4OdtJN0AxTP_nAeiUL6lY0l2hO38djLYDpMCjOMtJRU83-CV-_jXBixQ2g3jUyquua21emQuMWOG-gUXmCT29v3QcyWVbYTX1q9rXrpXnAPtZ4mdw65_hlrqiq35dX_g7zfTMjK-2mwZtF9mu5Wy66IsE8MK_gZZ_FZb4k6UQ1-YJiITEosaM5n-kk2djHI23DhA56Ghyh_UKBbOA31AvTMGAyGXURuRhunMdW1HFnZO6-zKY3ftdB4LDIR0-r1BPOzHQxaW888K6g5MVu65XJIBPYY3eWipNXwf02A--3SHsrVxTCc5zzK7Tcwns0qKG6rsUgQbcuPhVYEFpWfSQug-QORqttPiYUHxtDiM6cKS5vsFYsyZ_nF-ITvmOhLreD_KTzOIyTly480eY8LTG2Y9cL0MAeDRgbUzQmptMcULhB0J3F6b7bOqHrTcky6PMbheBKUXRnSbSIsFY_w-38h8aCKy0kYQ0" nonce="f2c81066605e7c336012f856c4fd7140" charset="UTF-8"></script><style type="text/css">body {width: 90%;margin-left: 5%;color: #666;font-family: Verdana;}.rack {width: 100%;float: left;margin-bottom: 1em;border: 1px solid;}.rack h2 {text-align: center;text-transform: uppercase;background-color: #278b31;color: #fff;margin: 0;padding: 1%;letter-spacing: 2px;}.book {border: 1px solid;padding: 5px;width: 30%;float: left;min-height: 200px;margin: 1%;background-color: #eaeaea;border-radius: 5%;}span.field {margin-right: 2px;color: #369ac9;}</style>
</head>
<body>
<div class="container">
<h1>MY LIBRARY</h1>
<xsl:for-each select="book[generate-id(.)=generate-id(key('division', genre))]">
<!-- <xsl:sort select="genre"/>-->
<div class="wall">
<!-- <Division value="{genre}">-->
<div class="rack">
<h2><xsl:value-of select="genre"/></h2>
<xsl:for-each select="key('division', genre) ">
<div class="book">
<div class="author">
<span class="field">Author: </span>
<span class="value"><xsl:value-of select="author"/></span>
</div>
<div class="title">
<span class="field">Title: </span>
<span class="value"><xsl:value-of select="title"/></span>
</div>
<div class="genre">
<span class="field">Genre: </span>
<span class="value"><xsl:value-of select="genre"/></span>
</div>
<div class="price">
<span class="field">Price: </span>
<span class="value"><xsl:value-of select="price"/></span>
</div>
<div class="publish_date">
<span class="field">Publish_date: </span>
<span class="value"><xsl:value-of select="publish_date"/></span>
</div>
<div class="description">
<span class="field">Description: </span>
<span class="value"><xsl:value-of select="description"/></span>
</div>
</div>
</xsl:for-each>
</div>
<!--</Division>-->
</div>
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>`
Разместим этот список вне вашего XSLT-файла. Скажем «заказ. xml». Код XSLT должен читать
это XML и располагать книги в таком порядке. У нас должна быть возможность изменить этот порядок, и если мы повторно запустим код XSLT, результат должен быть таким, как ожидалось. Если я изменю последовательность жанров по порядку. xml файл, в этой последовательности появится результат. как написать код
заказ. xml
<?xml version="1.0" encoding="UTF-8"?>
<order>
<genre>Fantasy</genre>
<genre>Science Fiction</genre>
<genre>Romance</genre>
<genre>Computer</genre>
<genre>Horror</genre>
</order>
plz help me sortout this problem