Reputation: 486
Hi I have xslt structure shown below
<xsl:template name="ConvertCriticalFlags">
<xsl:param name="src1"/>
<xsl:param name="src2"/>
<xsl:param name="src3"/>
<xsl:param name="src4"/>
<xsl:param name="src5"/>
<xsl:variable name="rslt" select="''"/>
<xsl:choose>
<xsl:when test="$src1 = 'YES'" >
<xsl:copy-of select="concat($rslt,',', '2TO4UNITS')"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="''"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$src2 = 'YES'">
<xsl:copy-of select="concat($rslt,',', 'COMMERCIAL')"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="''"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$src3 = 'YES'">
<xsl:copy-of select="concat($rslt,',', 'ACREAGE')"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="''"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$src4 = 'YES'">
<xsl:copy-of select="concat($rslt,',', 'MOBILEHOME')"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="''"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$src5 = 'YES'">
<xsl:copy-of select="concat($rslt,',', 'VACANTLAND')"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="''"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="starts-with($rslt,',') = true">
<xsl:copy-of select="substring($rslt,2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$rslt"/>
</xsl:otherwise>
</xsl:choose>
I would like to concatenate all the data into one variable $rslt
but i am unable to do so
Can any one suggest how to concatenate.
Upvotes: 1
Views: 1566
Reputation: 1
Define the all your choose condition in side one variable , that holds all the results.
Upvotes: -2
Reputation: 163595
<xsl:variable name="rslt" select="string-join((
'2TO4UNITS'[$src1 = 'YES'],
'COMMERCIAL'[$src2 = 'YES'],
'ACREAGE'[$src3 = 'YES'],
'MOBILEHOME'[$src4 = 'YES'],
'VACANTLAND'[$src5 = 'YES']), ',')"/>
Upvotes: 3
Reputation: 8774
<xsl:template name="ConvertCriticalFlags">
<xsl:param name="src1"/>
<xsl:param name="src2"/>
<xsl:param name="src3"/>
<xsl:param name="src4"/>
<xsl:param name="src5"/>
<xsl:variable name="rslt">
<xsl:if test="$src1 = 'YES'">,2TO4UNITS</xsl:if>
<xsl:if test="$src2 = 'YES'">,COMMERCIAL</xsl:if>
<xsl:if test="$src3 = 'YES'">,ACREAGE</xsl:if>
<xsl:if test="$src4 = 'YES'">,MOBILEHOME</xsl:if>
<xsl:if test="$src5 = 'YES'">,VACANTLAND</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="starts-with($rslt,',')">
<xsl:copy-of select="substring($rslt,2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$rslt"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Upvotes: 2
Reputation: 12729
To capture a sequence of nodes into a variable in XSLT 2.0, use this form...
<xsl:variable name="rslt">
... sequence constructors go here..
<xsl:variable>
... instead of the form ...
<xsl:variable name="rslt" select="bla bla bla" />
Upvotes: 0