Мне стыдно признаться, что я потратил 7 часов подряд, пытаясь сделать эту работу. Я хочу отсортировать вывод из первого узла, используя порядок второго узла.
XML
<?xml version="1.0" encoding="utf-8" ?>
<data>
<content>
<section link-id="86" link-handle="Start" value="Start" />
<section link-id="23" link-handle="george-orwell" value="Orwell, George" />
<section link-id="24" link-handle="aldous-huxley" value="Huxley, Aldous" />
<section link-id="26" link-handle="robert-lewis-stevenson" value="Stevenson, Robert Louis" />
</content>
<datasource>
<entry id="86">
<name handle="start">Start</name>
<order handle="0">0</order>
</entry>
<entry id="23">
<name handle="george-orwell">Orwell, George</name>
<order handle="1">1</order>
</entry>
<entry id="26">
<name handle="robert-lewis-stevenson">Stevenson, Robert Louis</name>
<order handle="2">2</order>
</entry>
<entry id="24">
<name handle="aldous-huxley">Huxley, Aldous</name>
<order handle="3">3</order>
</entry>
</datasource>
</data>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="sort-key" match="/data/datasource/entry" use="." />
<xsl:template match="data">
<html>
<body>
<xsl:apply-templates select="content" />
</body>
</html>
</xsl:template>
<xsl:template match="content">
<xsl:apply-templates select="section">
<xsl:sort select="key('sort-key', .)/@id"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="section">
Section: <xsl:value-of select="@value"/>
</xsl:template>
</xsl:stylesheet>
Текущий и неправильный вывод
<?xml version="1.0" encoding="utf-16"?>
<html><body>
Section: Start
Section: Orwell, George
Section: Huxley, Aldous
Section: Stevenson, Robert Louis</body>
</html>