0
votes

I have a Sharepoint list, and one of the columns is a lookup column that returns multiple values, separated by a semi-colon. I would like to display these items as separate lines in the output, instead of as a single line with the separator. The xsl for the field in question is as follows:

<xsl:template match="FieldRef[(@Encoded) and @Name='Project_x0020_Tasks']" ddwrt:dvt_mode="body" mode="Lookup_body" ddwrt:ghost="show">

            <xsl:param name="thisNode" select="."/>

<xsl:value-of select="$thisNode/@*[name()=current()/@Name]" disable-output-escaping="yes" />


</xsl:template>

currently the view displays the data inside a table cell as:

Task 1; Task 2; Task 3;

I would like it to display as

Task 1
Task 2
Task 3

I've spent plenty of hours searching online but haven't found any solution that helps me so far.

1

1 Answers

0
votes

What you could do is have a recursive template that converts semi-colons to <br /> tags, like so:

<xsl:template name="CharToLineBreak">
    <xsl:param name="text" />
    <xsl:param name="char" />
    <xsl:choose>
        <xsl:when test="contains($text, $char)">
            <xsl:value-of select="substring-before($text, $char)" />
            <br />
            <xsl:call-template name="CharToLineBreak">
                <xsl:with-param name="text" select="substring-after($text, $char)" />
                <xsl:with-param name="char" select="$char" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Then, instead of doing xsl:value-of as shown in your question, do xsl:call-template like so...

    <xsl:call-template name="CharToLineBreak">
        <xsl:with-param name="text" select="$thisNode/@*[name()=current()/@Name]" />
        <xsl:with-param name="char" select="';'" />
    </xsl:call-template>

I am not sure why you have so much complexity with getting the attribute value though. It could be simplified to just this

    <xsl:call-template name="CharToLineBreak">
        <xsl:with-param name="text" select="@Project_x0020_Tasks" />
        <xsl:with-param name="char" select="';'" />
    </xsl:call-template>