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.
\ 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.
Thanks, Anoop
<xsl:variable name="secondsegmentarray">
<item>Data/Attribute1</item>
<item>Data/Attribute2</item>
<item>Data/Attribute3</item>
<item>Data/Attribute4</item>
<item>Data/Attribute5</item>
<item>Data/Attribute6</item>
<item>Data/Attribute7</item>
</xsl:variable>
<xsl:variable name="secondsegment">
<xsl:value-of select="'\'">
<xsl:for-each select="secondsegmentarray/item">
<xsl:choose>
<xsl:when test="$secondsegmentarray.item = '' and secondsegment='\'"/>
</xsl:when>
<xsl:when test="$secondsegmentarray.item = not('') and secondsegment='\'"/>
<xsl:value-of select="concat($secondsegmentarray.item,secondsegment)"/>
</xsl:when>
<xsl:when test="$secondsegmentarray.item = not('') and secondsegment!='\'"/>
<xsl:value-of select="concat($secondsegmentarray.item,'*',secondsegment)"/>
</xsl:when>
<xsl:when test="$secondsegmentarray.item = '' and secondsegment!='\'"/>
<xsl:value-of select="concat('*',secondsegment)"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:variable/>
$secondsegmentarraywill be of Result Tree Fragment type (the worst decision about the language specification). And then, of course, you cannot iterate over a Result Tree Fragment (from the spec): "An operation is permitted on a result tree fragment only if that operation would be permitted on a string [..]. In particular, it is not permitted to use the/,//, and[]operators on result tree fragments".