title: Problems generating SOAP XML using XSLT
body: <p>I am using XSLT to transform some provisioning XML into a SOAP request. But I am having difficulties finding an approach that does not require full XPATH expressions and still generates valid SOAP XML.</p>
  
  <p>Here is a simplified version of the provisioning XML.</p>
  
  <pre><code>&lt;CreateOrder&gt;
      &lt;client_info&gt;
          &lt;name&gt;John Doe&lt;/name&gt;
          &lt;address&gt;
              &lt;street1&gt;1211 Lakeview Dr.&lt;/street1&gt;
              &lt;city&gt;New York&lt;/city&gt;
              &lt;state&gt;NY&lt;/state&gt;
              &lt;country&gt;USA&lt;/country&gt;
              &lt;zip&gt;12345&lt;/zip&gt;
          &lt;/address&gt;
      &lt;/client_info&gt;
      &lt;subscriber_number&gt;AAANNNDDDD&lt;/subscriber_number&gt;
  &lt;/CreateOrder&gt;
  </code></pre>
  
  <p>And here is the simplified XSLT I am using.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
      &lt;xsl:output method="xml" /&gt;
      &lt;xsl:template match="/"&gt;
          &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
              &lt;soapenv:Header/&gt;
              &lt;soapenv:Body&gt;
                  &lt;DirectoryNumber&gt;&lt;xsl:value-of select="CreateOrder/subscriber_number"/&gt;&lt;/DirectoryNumber&gt;
                  &lt;Locale&gt;
                      &lt;xsl:choose&gt;
                          &lt;xsl:when test="CreateOrder/client_info/address/country = 'USA'"&gt;
                              &lt;xsl:text&gt;English (US)&lt;/xsl:text&gt;
                          &lt;/xsl:when&gt;
                          &lt;xsl:otherwise&gt;
                              &lt;xsl:text&gt;User Defined 1&lt;/xsl:text&gt;
                          &lt;/xsl:otherwise&gt;
                      &lt;/xsl:choose&gt;
                  &lt;/Locale&gt;
              &lt;/soapenv:Body&gt;
          &lt;/soapenv:Envelope&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This generates the following XML output - which is what I expected / want. [Note that I had to pretty printed this - my output is actually just a single line wth no line breaks / indents.]</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soapenv:Header/&gt;
      &lt;soapenv:Body&gt;
          &lt;DirectoryNumber&gt;
              AAANNNDDDD
          &lt;/DirectoryNumber&gt;
          &lt;Locale&gt;
              English (US)
          &lt;/Locale&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>By playing around, it appears that I need to use <code>&lt;xsl:template match="/"&gt;</code> to match the whole input document, or else I do not get the SOAP XML into the output. Is there some other way of generating a sequence of new XML from the XSLT?</p>
  
  <p>But when the <code>&lt;xsl:template match="/"&gt;</code> is present, I can't nest other <code>&lt;xsl:template match=..."&gt;</code> elements (for example to match "address") and so have to use full XPATH node expressions (such as <code>CreateOrder/client_info/address/country</code>) in the tests. This works but is not particularly elegant, and is somewhat error prone for a real world longer example. Is there a better way of doing this?</p>