title: XSLT Error with output String manipulation
body: <p>I have create an XSLT that looks for the month tag in the following input and splits the string and creates new tags for each. However the issue i am having is that it is only looking at the first month tag and for any subsiquent <code>&lt;set&gt;</code> tags it auto fills them with the result from the first set.</p>
  
  <p>So for this input:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF8"?&gt;
   &lt;Response xmlns="http://www.castiron.com/response"&gt;
       &lt;payload&gt;
           &lt;sets&gt;
               &lt;month&gt;JUN,JUL&lt;/month&gt;
               &lt;season&gt;Season11&lt;/season&gt;
               &lt;productId&gt;1111111&lt;/productId&gt;
           &lt;/sets&gt;
           &lt;sets&gt;
              &lt;month&gt;AUG,SEP&lt;/month&gt;
              &lt;season&gt;Season12&lt;/season&gt;
              &lt;productId&gt;2222222&lt;/productId&gt;
          &lt;/sets&gt; 
      &lt;/payload&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>It <strong>SHOULD</strong> produce:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Response xmlns="http://www.castiron.com/response"&gt;
      &lt;payload xmlns:r="http://www.castiron.com/response"&gt;
          &lt;sets&gt;
              &lt;month&gt;JUN&lt;/month&gt;
              &lt;season&gt;Season11&lt;/season&gt;
              &lt;productId&gt;1111111&lt;/productId&gt;
          &lt;/sets&gt;
          &lt;sets&gt;
              &lt;month&gt;JUL&lt;/month&gt;
              &lt;season&gt;Season11&lt;/season&gt;
              &lt;productId&gt;1111111&lt;/productId&gt;
          &lt;/sets&gt;
          &lt;sets&gt;
              &lt;month&gt;AUG&lt;/month&gt;
              &lt;season&gt;Season12&lt;/season&gt;
              &lt;productId&gt;2222222&lt;/productId&gt;
          &lt;/sets&gt;
          &lt;sets&gt;
              &lt;month&gt;SEP&lt;/month&gt;
              &lt;season&gt;Season12&lt;/season&gt;
              &lt;productId&gt;2222222&lt;/productId&gt;
          &lt;/sets&gt;
      &lt;/payload&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>However its <strong>ACTUAL</strong> Response is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Response xmlns="http://www.castiron.com/response"&gt;
      &lt;payload xmlns:r="http://www.castiron.com/response"&gt;
          &lt;sets&gt;
              &lt;month&gt;JUN&lt;/month&gt;
              &lt;season&gt;Season11&lt;/season&gt;
              &lt;productId&gt;1111111&lt;/productId&gt;
          &lt;/sets&gt;
          &lt;sets&gt;
              &lt;month&gt;JUN&lt;/month&gt;
              &lt;season&gt;Season12&lt;/season&gt;
              &lt;productId&gt;2222222&lt;/productId&gt;
          &lt;/sets&gt;
          &lt;sets&gt;
              &lt;month&gt;JUL&lt;/month&gt;
              &lt;season&gt;Season11&lt;/season&gt;
              &lt;productId&gt;1111111&lt;/productId&gt;
          &lt;/sets&gt;
          &lt;sets&gt;
              &lt;month&gt;JUL&lt;/month&gt;
              &lt;season&gt;Season12&lt;/season&gt;
              &lt;productId&gt;2222222&lt;/productId&gt;
          &lt;/sets&gt;
      &lt;/payload&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>The current XSLT is:</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:strip-space elements="*"/&gt;
  
      &lt;xsl:template match="@* | node()"&gt;
          &lt;xsl:param name="month"/&gt;
  
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@* | node()"&gt;
                  &lt;xsl:with-param name="month" select="$month"/&gt;
              &lt;/xsl:apply-templates&gt;
          &lt;/xsl:copy&gt;
  
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="r:month"&gt;
          &lt;xsl:param name="month"/&gt;
          &lt;month xmlns="http://www.castiron.com/response"&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="$month"&gt;
                      &lt;xsl:value-of select="$month"/&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:apply-templates/&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/month&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name="splitMonths"&gt;
          &lt;xsl:param name="months"/&gt;
          &lt;xsl:variable name="firstMonth" select="substring-before($months,',')"/&gt;
          &lt;xsl:variable name="month"&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="$firstMonth"&gt;
                      &lt;xsl:value-of select="$firstMonth"/&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:value-of select="$months"/&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:variable&gt;
          &lt;xsl:variable name="otherMonths" select="substring-after($months,',')"/&gt;
          &lt;xsl:if test="$month"&gt;
              &lt;xsl:apply-templates&gt;
                  &lt;xsl:with-param name="month" select="$month"/&gt;
              &lt;/xsl:apply-templates&gt;
          &lt;/xsl:if&gt;
          &lt;xsl:if test="$otherMonths"&gt;
              &lt;xsl:call-template name="splitMonths"&gt;
                  &lt;xsl:with-param name="months" select="$otherMonths"/&gt;
              &lt;/xsl:call-template&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="r:payload"&gt;
  
          &lt;payload xmlns="http://www.castiron.com/response"&gt;
  
              &lt;xsl:call-template name="splitMonths"&gt;
                  &lt;xsl:with-param name="months" select="r:sets/r:month"/&gt;
              &lt;/xsl:call-template&gt;
  
          &lt;/payload&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Can anyone help as i have been racking my brain around this one for days!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I was looking at the idea of looping through each <code>&lt;sets&gt;</code> tag and therefore use this section in the fill code above:</p>
  
  <pre><code>&lt;xsl:template match="r:payload"&gt;
      &lt;payload xmlns="http://www.castiron.com/response"&gt;
          &lt;xsl:for-each select="r:sets"&gt;
  
          &lt;xsl:call-template name="splitMonths"&gt;
              &lt;xsl:with-param name="months" select="r:sets/r:month"/&gt; 
          &lt;/xsl:call-template&gt;
  
          &lt;/xsl:for-each&gt;
      &lt;/payload&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>However it produces the following output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Response xmlns="http://www.castiron.com/response"&gt;
      &lt;payload xmlns:r="http://www.castiron.com/response"&gt;
          &lt;month/&gt;
          &lt;season&gt;SS11&lt;/season&gt;
          &lt;productId&gt;3600596&lt;/productId&gt;
          &lt;month/&gt;
          &lt;season&gt;AW12&lt;/season&gt;
          &lt;productId&gt;7001258&lt;/productId&gt;
      &lt;/payload&gt;
  &lt;/Response&gt;
  </code></pre>