title: Loop and concatenate an array in xslt
body: <p>I am trying to loop an array and concatenate the non null values to a single variable. Needless to say I am new to XSLT. Please see the code that I wrote and let me know the best way to do this.</p>
  
  <p>\ is to be appended at the end and also I have to add a separator * between the values. If * and \ are coming together, then only \ should come and we can omit the *. I believe the logic is correct. The syntax is the issue.</p>
  
  <p>Thanks,
  Anoop</p>
  
  <pre><code>&lt;xsl:variable name="secondsegmentarray"&gt;
      &lt;item&gt;Data/Attribute1&lt;/item&gt;
      &lt;item&gt;Data/Attribute2&lt;/item&gt;
      &lt;item&gt;Data/Attribute3&lt;/item&gt;
      &lt;item&gt;Data/Attribute4&lt;/item&gt;
      &lt;item&gt;Data/Attribute5&lt;/item&gt;
      &lt;item&gt;Data/Attribute6&lt;/item&gt;
      &lt;item&gt;Data/Attribute7&lt;/item&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:variable name="secondsegment"&gt;
      &lt;xsl:value-of select="'\'"&gt;
      &lt;xsl:for-each select="secondsegmentarray/item"&gt;
          &lt;xsl:choose&gt;
           &lt;xsl:when test="$secondsegmentarray.item = '' and secondsegment='\'"/&gt;
           &lt;/xsl:when&gt;
           &lt;xsl:when test="$secondsegmentarray.item = not('') and secondsegment='\'"/&gt;
             &lt;xsl:value-of select="concat($secondsegmentarray.item,secondsegment)"/&gt;
           &lt;/xsl:when&gt;
           &lt;xsl:when test="$secondsegmentarray.item = not('') and secondsegment!='\'"/&gt;
             &lt;xsl:value-of select="concat($secondsegmentarray.item,'*',secondsegment)"/&gt;
           &lt;/xsl:when&gt;
           &lt;xsl:when test="$secondsegmentarray.item = '' and secondsegment!='\'"/&gt;
             &lt;xsl:value-of select="concat('*',secondsegment)"/&gt;
           &lt;/xsl:when&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:for-each&gt;
  &lt;xsl:variable/&gt;
  </code></pre>