title: Parsing and storing values in array in XSLT 1.0
body: <p>Thanks in advance for your support. I was just stuck with a problem and tried a lot in all ways.</p>
  
  <p>I have an XSLT 1.0 that need to parse the value of an xml tag by comma and store it in array.</p>
  
  <p>&lt;OPTIONS>val1,,val2,val3,,,val4&lt;/OPTIONS></p>
  
  <p>Here I need to parse the OPTIONS field value by comma and then store it in array. Here I was stuck with the way of storing it in array for further use.</p>
  
  <p>Please advice</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0"&gt;
      &lt;xsl:output method="text" omit-xml-declaration="yes"/&gt;
      &lt;xsl:variable name="inline-array"&gt;
          &lt;!--&lt;Item&gt;A&lt;/Item&gt;
          &lt;Item&gt;B&lt;/Item&gt;
          &lt;Item&gt;C&lt;/Item&gt;--&gt;
  
          &lt;xsl:call-template name="splitByComma"&gt;
              &lt;xsl:with-param name="str" select="OPTIONS"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:variable&gt;
  
      &lt;xsl:template match="/"&gt;
          &lt;xsl:param name="array" select="document('')/*/xsl:variable[@name='inline-array']/*"/&gt;
          &lt;xsl:value-of select="$array[1]"/&gt;          
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name="splitByComma"&gt;
          &lt;xsl:param name="str"/&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="contains($str,',')"&gt;
                  &lt;item&gt;&lt;xsl:value-of select="substring-before($str,',')"/&gt;&lt;/item&gt;
                  &lt;xsl:call-template name="splitByComma"&gt;
                      &lt;xsl:with-param name="str"
                          select="substring-after($str,',')"/&gt;
                  &lt;/xsl:call-template&gt;
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;item&gt;&lt;xsl:value-of select="$str"/&gt;&lt;/item&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>