Francesco Irrera
Francesco Irrera

Reputation: 473

Concat string value with a separator Xslt 1.0

This is my XML:

<LIGHT_INFORMATION_LIST>
    <LIGHT_INFORMATION>
        <LIGHT_CHARACTERISTICS>Al</LIGHT_CHARACTERISTICS>
        <LIGHT_COLOUR>W-G</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
    <LIGHT_INFORMATION>
        <LIGHT_CHARACTERISTICS>Al</LIGHT_CHARACTERISTICS>
        <LIGHT_COLOUR>W-R</LIGHT_COLOUR>
    </LIGHT_INFORMATION>
</LIGHT_INFORMATION_LIST>

I would concat all element of LIGHT_COLOUR in a variable separate by '-'.

In output I desire: W-G-W-R (assigned in a variable).

I created this:

<xsl:value-of select="concat(LIGHT_COLOUR,'-')"/>  -->Output W-G-W-R-

Now I would assign to a variable this output.

Upvotes: 0

Views: 3351

Answers (2)

Francesco Irrera
Francesco Irrera

Reputation: 473

<xsl:variable name="concatenazione" select="concat(LIGHT_COLOUR,'-')"/>
<xsl:value-of select="$concatenazione"/>

Upvotes: 0

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

try something like this:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

    <xsl:variable name="Colours">
        <xsl:for-each select="/LIGHT_INFORMATION_LIST/LIGHT_INFORMATION/LIGHT_COLOUR">
            <xsl:if test="position() > 1">
                <xsl:text>-</xsl:text>
            </xsl:if>
            <xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:variable>

    <xsl:template match="/">
        <xsl:value-of select="$Colours"/>
    </xsl:template>

</xsl:stylesheet>

Upvotes: 1

Related Questions