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.

  exclude-result-prefixes="x d xsl msxsl cmswrt"

<!-- Accordion Template -->

<xsl:template name="Accordion" match="Row[@Style='Accordion']" mode="itemstyle">

    <div class="accordion-header">      
        <xsl:value-of select="concat(@Title,'  |  ',@dateFormat, '  |  ', @Author)"/>

    <xsl:variable name="varAnswered" select="@Answered"/> <!--Answered = yes/no column -->

         <xsl:when test="$varAnswered = 'Yes'">      
         <div class="accordion-content">     
         <xsl:value-of select="concat(@Title,'  |  ',@dateFormat, '  |  ', @Author)"/>

         <div class="accordion-content">     
         <xsl:value-of select="@Title"/>



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)"/>

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.

  • Show us the code that doesn't work (not code that does), together with representative input data, and we should be able to quickly spot what you did wrong. It doesn't help that you are using words like "field" and "column" that have no meaning in an XML context. We can only guess whether you mean elements, attributes, or something else. Dec 4, 2018 at 11:00
  • I've added a snippet to show how I've tried to assign a Sharepoint column to a variable to then test the IF condition. I'm trying to use the column value to determine which XSL select statement to display. Hopefully that makes sense.
    – cod3r_jim
    Dec 4, 2018 at 11:18
  • There's still not enough context here to see where your code is wrong. You haven't shown any XML input, and you haven't shown enough of the XSLT to see what the context node is at the point where you access the @Answered attribute. (Context is all-important in XSLT, and the fact that you haven't realised this information is important for diagnosis is itself a hint that this is where the error might be.) Dec 4, 2018 at 14:28
  • Feels like this being over-complicated needlessly now. I simply need the correct syntax for performing an IF statement within the XSLT. If I remove the IF statement, I can populate both accordion divs with no issue. I can appreciate context is vital but I've clearly shown which part of my code is not working and requested advice on what the syntax should be to correctly use a SharePoint column within the IF statement.
    – cod3r_jim
    Dec 4, 2018 at 14:53
  • There's nothing wrong with your syntax. If there was, you would presumably tell us the error message. There's something wrong with the semantics, and I've told you that this is most likely something to do with the context. I can't help you any more unless you give me the information that I ask for. Dec 4, 2018 at 17:35

1 Answer 1


After tinkering with the code, the issue was simply the syntax placement. I was trying to execute the If statement outside of the DIV instead of inside of it.

<div class="accordion-content">
        <xsl:if test="$numbertwo &gt; $numberone">
        <xsl:value-of select="concat(@Body,'  |  ',@dateFormat2, '  |  answered by ', @Editor)" />

This resolved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.