title: Merge two xml schemas using XSLT
body: <p>I'm transforming an XML Schema using XSLT 2.0. The first schema (s1.xsd) imports a second schema (s2.xsd) as follows:</p>
  
  <p>Content of s1.xsd</p>
  
  <pre><code>&lt;schema xmlns="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema.xsd"
      xmlns:ns1="URI1" targetNamespace="URI2" 
      elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
      &lt;import namespace="URI1" schemaLocation="s2.xsd"/&gt;
      &lt;element name="element1"/&gt;
      &lt;element name="element2"/&gt;
  &lt;/schema&gt;
  </code></pre>
  
  <p>and content of s2.xsd</p>
  
  <pre><code>&lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:ns1="URI1" targetNamespace="URI1"&gt;
      &lt;attribute name="attr1"/&gt;
  &lt;schema&gt;
  </code></pre>
  
  <p>My XSLT declares the XS namespace as follows:</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;  
  </code></pre>
  
  <p>I would like to merge the nodes of s2.xsd into the &lt;schema&gt;-element of s1.xsd. So far, I've tried</p>
  
  <pre><code>&lt;xsl:template name="merge_imported_schemas"&gt;
      &lt;xsl:for-each select="/schema/import[@namespace = //namespace::*]"&gt;
          &lt;!-- file exists? --&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="boolean(document(@schemaLocation))"&gt;
                  &lt;!-- schema found --&gt;
                  &lt;xsl:copy-of select="document(@schemaLocation)/*/node()"/&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;!-- schema not found --&gt;
                  &lt;xsl:message terminate="yes"&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>but I don't get the desired result. Could anyone please tell me what I'm doing wrong? I suspect there is a namespace-collision here, but honestly I find using namespaces a little confusing. Thanks!</p>