title: XSLT - How to combine XSLT files
body: <p>Is there a simple way of combining XSLT's. I am new to XSLT, and i getting the hang of how to create them and the funny ways of using them to get my desired outcome. However at the moment I am able to use one XSLT to convert my output into the desired output; <strong>BUT</strong> then straight after it i have another, and another. Each XSLT changes the output from one thing to another.</p>
  
  <p>For example, and these are simple XSLTs to illustrate the issue:</p>
  
  <p>XSLT 1:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:r="http://www.castiron.com/response" exclude-result-prefixes="r"&gt;
  
      &lt;xsl:output method="xml" indent="yes"/&gt;
  
      &lt;xsl:template match="/root"&gt;
          &lt;xsl:element name="imageScene7Response"  xmlns="http://www.castiron.com/burberry/digitalcatalogue/response"&gt;
              &lt;xsl:element name="rcode"&gt;0&lt;/xsl:element&gt;
              &lt;xsl:element name="rmessage"&gt;success&lt;/xsl:element&gt;
              &lt;xsl:copy-of select="@*"/&gt;
              &lt;xsl:apply-templates select="payload"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="/root/payload"&gt;
          &lt;xsl:if test="not(productId = preceding-sibling::payload/productId)"&gt;
  
              &lt;xsl:element name="payload" xmlns="http://www.castiron.com/burberry/digitalcatalogue/response"&gt;
                  &lt;xsl:element name="productId"&gt;
                      &lt;xsl:value-of select="productId"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:for-each select="../payload[productId = current()/productId]"&gt;
                      &lt;xsl:choose&gt;
                          &lt;xsl:when test="type = '0' and preceding-sibling::payload/type = type and productId = preceding-sibling::payload/productId"&gt;
                              &lt;xsl:element name="alternativeImages"&gt;
                                  &lt;xsl:value-of select="url"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:when&gt;
                          &lt;xsl:when test="type = '0'"&gt;
                              &lt;xsl:element name="mainImage"&gt;
                                  &lt;xsl:value-of select="url"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:when&gt;
                          &lt;xsl:when test="type &amp;gt; '0' and type &amp;lt; '70'"&gt;
                              &lt;xsl:element name="alternativeImages"&gt;
                                  &lt;xsl:value-of select="url"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:when&gt;
                          &lt;xsl:when test="type = '70'"&gt;
                              &lt;xsl:element name="video"&gt;
                                  &lt;xsl:value-of select="url"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:when&gt;
                          &lt;xsl:when test="type = '80'"&gt;
                              &lt;xsl:element name="lookbookImages"&gt;
                                  &lt;xsl:value-of select="url"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:when&gt;
                          &lt;xsl:when test="type = 'sw'"&gt;
                              &lt;xsl:element name="swatchImages"&gt;
                                  &lt;xsl:value-of select="url"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:when&gt;
                      &lt;/xsl:choose&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/xsl:element&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt;
      &lt;xsl:strip-space elements="*"/&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=
          "*[not(@*|*|comment()|processing-instruction()) 
          and normalize-space()=''
          ]"/&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Then some other logic in other XSLT.</p>
  
  <p>Is it as easy as putting the templates one below another in a single combined XSLT?</p>
  
  <p><em><strong>XML SNIPT</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root&gt;
      &lt;payload&gt;
          &lt;productId&gt;11111&lt;/productId&gt;
          &lt;type&gt;0&lt;/type&gt;
          &lt;url&gt;https://11111&lt;/url&gt;
      &lt;/payload&gt;
      &lt;payload&gt;
          &lt;productId&gt;11111&lt;/productId&gt;
          &lt;type&gt;1&lt;/type&gt;
          &lt;url&gt;https://11111&lt;/url&gt;
      &lt;/payload&gt;
      &lt;payload&gt;
          &lt;productId&gt;11111&lt;/productId&gt;
          &lt;type&gt;1&lt;/type&gt;
          &lt;url&gt;&lt;/url&gt;
      &lt;/payload&gt;
      &lt;payload&gt;
          &lt;productId&gt;22222&lt;/productId&gt;
          &lt;type&gt;0&lt;/type&gt;
          &lt;url&gt;https://22222&lt;/url&gt;
      &lt;/payload&gt;
      &lt;payload&gt;
          &lt;productId&gt;22222&lt;/productId&gt;
          &lt;type&gt;1&lt;/type&gt;
          &lt;url&gt;https://22222&lt;/url&gt;
      &lt;/payload&gt;
      &lt;payload&gt;
          &lt;productId&gt;22222&lt;/productId&gt;
          &lt;type&gt;sw&lt;/type&gt;
          &lt;url&gt;https://22222&lt;/url&gt;
      &lt;/payload&gt;
      &lt;payload&gt;
          &lt;productId&gt;22222&lt;/productId&gt;
          &lt;type&gt;sw&lt;/type&gt;
          &lt;url&gt;&lt;/url&gt;
      &lt;/payload&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>This isnt the best example, but it will work!</p>