locked
How can I use Xpath to count items in a SharePoint list but limit the count results to other values in the SP list? RRS feed

  • Question

  • OK I have a list in SP which captures quiz results and want to be able to report on the results in a DVWP...So i have created my DVWP and included a formula column to count results which displays a list as follows

    Quiz Question Correct Answer Text Number Correct
    ABC Who, what, why Why 50
    ABC When, Where, How When 50
    BCD Left, Right Right 50
    BCD Up, Down Down 50

    What i am trying to acheive here is to calculate the number of each question correct, however all i seem to get is a count of ALL questions answered correctly.

    The count is based on a column titled MarkAnswers which contains a '1' if the question was answered correctly i.e. it counts the number of 1s in the column.

    My question therefore is how do i adjust the expression count(//@MarkAnswers[.=1]) so that it will effectively group the results by the colum headings @Quiz and @Question and display just the number correctly answered for each question i.e. to display like this

    Quiz Question Correct Answer Text Number Correct
    ABC Who, what, why Why 23
    ABC When, Where, How When 17
    BCD Left, Right Right 5
    BCD Up, Down Down 5

    Any help on this would be fantastic!

     

    • Moved by Mike Walsh FIN Wednesday, April 27, 2011 6:08 AM DVWP and XPath = customization not programming (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Tuesday, April 26, 2011 11:28 PM

Answers

  • Hi,

    Thanks to share your post.

    For the issue, my suggestion is to consider this statement:

    Foreach(int i, listview.items[“@MarkAnswers”].subitems)

    {

       If( listview.items[“@MarkAnswers”].subitems.string[i]=1);

       Listviw.items[“number correct”].subitems.string[i]++;

    }

    Hope this could help you!

    Leo

     

    • Marked as answer by Emir Liu Thursday, May 5, 2011 10:13 AM
    Friday, April 29, 2011 9:27 AM
  • Hi,

    Thanks to share your post.

    For the issue, my suggestion is to consider this statement:

    Foreach(int i, listview.items[“@MarkAnswers”].subitems)

    {

       If( listview.items[“@MarkAnswers”].subitems.string[i]=1);

       Listviw.items[“number correct”].subitems.string[i]++;

    }

    Hope this could help you!

    Leo

     


    Hey Leo,

    Thank you for your response. Still being a bit of a nube to the world of SP development I am not 100% sure how to actually put your suggested solution into the page code correctly and therefore have been unable to test if it will work for me or not. Should i be using the Xpath Expression builder for such things or does this need to go directly into the code view using other xml tags etc?

    After some further research (i.e. scouring the web and reading an huge amount of unhelpful information) I managed to find a very simple solution which was to use the addition of a current() statement in the expression. So the expression worked perfectly when changed to:

    count(/dsQueryResponse/Rows/Row[@Question=current()/@Question]/@MarkAnswer[.=1])

    Many thanks

    D


    D Man
    • Marked as answer by Emir Liu Thursday, May 5, 2011 10:13 AM
    Sunday, May 1, 2011 8:49 PM

All replies

  • Hi,

    Thanks to share your post.

    For the issue, my suggestion is to consider this statement:

    Foreach(int i, listview.items[“@MarkAnswers”].subitems)

    {

       If( listview.items[“@MarkAnswers”].subitems.string[i]=1);

       Listviw.items[“number correct”].subitems.string[i]++;

    }

    Hope this could help you!

    Leo

     

    • Marked as answer by Emir Liu Thursday, May 5, 2011 10:13 AM
    Friday, April 29, 2011 9:27 AM
  • Hi,

    Thanks to share your post.

    For the issue, my suggestion is to consider this statement:

    Foreach(int i, listview.items[“@MarkAnswers”].subitems)

    {

       If( listview.items[“@MarkAnswers”].subitems.string[i]=1);

       Listviw.items[“number correct”].subitems.string[i]++;

    }

    Hope this could help you!

    Leo

     


    Hey Leo,

    Thank you for your response. Still being a bit of a nube to the world of SP development I am not 100% sure how to actually put your suggested solution into the page code correctly and therefore have been unable to test if it will work for me or not. Should i be using the Xpath Expression builder for such things or does this need to go directly into the code view using other xml tags etc?

    After some further research (i.e. scouring the web and reading an huge amount of unhelpful information) I managed to find a very simple solution which was to use the addition of a current() statement in the expression. So the expression worked perfectly when changed to:

    count(/dsQueryResponse/Rows/Row[@Question=current()/@Question]/@MarkAnswer[.=1])

    Many thanks

    D


    D Man
    • Marked as answer by Emir Liu Thursday, May 5, 2011 10:13 AM
    Sunday, May 1, 2011 8:49 PM