title: XSL to Flatten JAX-WS WSDL
body: <p>I have several JAX-WS generated WSDLs which include an xsd:import, one of the clients isn't capable of stitching the two together, so I'm looking to flatten the WSDL into a single file.</p>
  
  <p>I have this WSDL:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://mypackage.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://mypackage.com/" name="ws"&gt;
      &lt;types&gt;
          &lt;xsd:schema&gt;
              &lt;xsd:import namespace="http://mypackage.com/" schemaLocation="the.xsd"/&gt;
          &lt;/xsd:schema&gt;
      &lt;/types&gt;
      &lt;!-- ... --&gt;
  &lt;/definitions&gt;
  </code></pre>
  
  <p>and the referenced XSD:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  
  &lt;xs:schema xmlns:tns="http://mypackage.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://mypackage.com/"&gt;
  
      &lt;xs:element name="getSomething" type="tns:getSomething"/&gt;
  
      &lt;xs:element name="getSomethingResponse" type="tns:getSomethingResponse"/&gt;
  
      &lt;xs:complexType name="getSomething"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="blahOne" type="xs:string" minOccurs="0"/&gt;
              &lt;xs:element name="blahTwo" type="xs:int"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="getSomethingResponse"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="return" type="xs:string" minOccurs="0"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>and the XSL I'm using to transform:</p>
  
  <pre><code>&lt;xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      version="1.0"&gt;
      &lt;xsl:output method="xml" indent="no"/&gt;
      &lt;xsl:template match="node() | @*"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="node() | @*"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;    
      &lt;xsl:template match="xs:import"&gt;
          &lt;xsl:variable name="schema" select="@schemaLocation"/&gt;
          &lt;xsl:apply-templates select="document($schema)"/&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Gives the result:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://mypackage.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://mypackage.com/" name="ws"&gt;
      &lt;types&gt;
          &lt;xsd:schema&gt;
              &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://mypackage.com/"&gt;
  
                  &lt;xs:element name="getSomething" type="tns:getSomething"/&gt;
  
                  &lt;xs:element name="getSomethingResponse" type="tns:getSomethingResponse"/&gt;
  
  
                  &lt;xs:complexType name="getSomething"&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="blahOne" type="xs:string" minOccurs="0"/&gt;
                          &lt;xs:element name="blahTwo" type="xs:int"/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
  
                  &lt;xs:complexType name="getSomethingResponse"&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element name="return" type="xs:string" minOccurs="0"/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
  
  
              &lt;/xs:schema&gt;
          &lt;/xsd:schema&gt;
      &lt;/types&gt;
      &lt;!-- ... --&gt;
  &lt;/definitions&gt;
  </code></pre>
  
  <p>... and the problem is that I need to have the targetNamespace="http://mypackage.com/" defined on the outer: xsd:schema, or alternatively if I could drop the  tags and somehow convert the xsd namespace prefix from "xs" to "xsd", what am I doing wrong?</p>