I have a custom Content Query web part that I'm using to display my JQuery Q&A functionality. I'm using a XSL file to determine what display as my question and answer headers.
What I want to do is to only display the Answer select statement if the question has been answered
I've tried various ways including using xsl multi-line filters (Answer is a multiline text column) but struggled. I figured the easiest way for me was to simply use an existing column that is set when a Question is answered.
It is a Yes/No column, but I've also tested single line and calculated columns and still ran into the same issues.
<xsl:stylesheet version="1.0" exclude-result-prefixes="x d xsl msxsl cmswrt" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <!-- Accordion Template --> <xsl:template name="Accordion" match="Row[@Style='Accordion']" mode="itemstyle"> <div class="accordion-header"> <xsl:value-of select="concat(@Title,' | ',@dateFormat, ' | ', @Author)"/> </div> <xsl:variable name="varAnswered" select="@Answered"/> <!--Answered = yes/no column --> <xsl:choose> <xsl:when test="$varAnswered = 'Yes'"> <div class="accordion-content"> <xsl:value-of select="concat(@Title,' | ',@dateFormat, ' | ', @Author)"/> </div> </xsl:when> <xsl:otherwise> <div class="accordion-content"> <xsl:value-of select="@Title"/> </div> </xsl:otherwise> </xsl:choose> </xsl:template>
My issue is possibly the syntax for using an existing column as a variable.
<xsl:variable name="varAnswered" select="@Answered"/>
Is the above syntax the correct away to assign a SharePoint column to a variable? The IF statement compares the result of the Yes/No column, but it doesn't return a correct response for when the variable = Yes.
If my list item has @Answered = Yes, then the IF statement should return the full concat statement, but it still returns the single @Title select statement. So the IF statement is not comparing correctly.
This is why I'm thinking there's either something wrong with the way I'm assigning the column or the IF statement syntax itself.
<xsl:when test="$varAnswered = 'Yes'"> <div class="accordion-content"> <xsl:value-of select="concat(@Title,' | ',@dateFormat, ' | ', @Author)"/> </div> </xsl:when>
This is the statement that does not return true even when the variable based on the SharePoint column equals "Yes" So it should be vaAnswered(Yes) = Yes and should return true but doesn't so then executes the Otherwise statement.
I've tried so many varieties of declaring variables and changing the IF statements but can't get it to perform correctly using a SharePoint column value.
What is the correct syntax for storing a SharePoint column as a variable to then perform the IF statement? Or can I use the SharePoint column (@Answered) directly in the IF statement?
I'm new to XSLT, so any help is greatly appreciated.