title: Merge and sort multiple XML Files with XSL
body: <p>The problem is to merge and sort multiple XML files with XSL and output valid HTML, viewable with Firefox >=3.5 and if possible IE >=7. The answer should be as simple as possible (performance is not important).</p>
  
  <p>File a.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root&gt;
      &lt;tag&gt;cc&lt;/tag&gt;
      &lt;tag&gt;aa&lt;/tag&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>File b.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root&gt;
      &lt;tag&gt;xx&lt;/tag&gt;
      &lt;tag&gt;bb&lt;/tag&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>File index.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="merge.xslt"?&gt;
  &lt;list&gt;
      &lt;entry&gt;a.xml&lt;/entry&gt;
      &lt;entry&gt;b.xml&lt;/entry&gt;
  &lt;/list&gt;
  </code></pre>
  
  <p>File merge.xslt</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ph="http://ananas.org/2003/tips/photo"&gt;
  
      &lt;xsl:output method="html"/&gt;
  
      &lt;xsl:template match="list"&gt;
          &lt;html&gt;
              &lt;body&gt;
                  &lt;xsl:apply-templates/&gt;
              &lt;/body&gt;
          &lt;/html&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="entry"&gt;
          &lt;xsl:for-each select="document(.)/root/tag"&gt;
              &lt;!-- This will only sort the values of a single file --&gt;
              &lt;xsl:sort select="." data-type="text" order="ascending" /&gt;
              - &lt;xsl:value-of select="."/&gt; &lt;br/&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Current output:</p>
  
  <ul>
  <li><p>aa</p></li>
  <li><p>cc</p></li>
  <li><p>bb</p></li>
  <li><p>xx</p></li>
  </ul>
  
  <p>Expected output:</p>
  
  <ul>
  <li><p>aa</p></li>
  <li><p>bb</p></li>
  <li><p>cc</p></li>
  <li><p>xx</p></li>
  </ul>