Filtering XSLT in a dataviewer with lookup column

1k Views Asked by At

I have two lists, quizzes, and quiz questions in SharePoint. Quiz questions has a lookup column pointed to quizzes and includes a column for the originating list's row ID (quiz ID). I want to create a data viewer part with some custom XSLT and am just about finished but cannot get the final query to work quite correctly whereby I want to get all quiz questions for a quiz ID.

First I created a datasource in SPD and included both lists (linked). I then inserted a new Data View on my page and included the datasource. The hierarchy for my field looks correct in SPD:

/dsQueryResponse/QuizQuestions/Rows/Row/@Quiz_x003a_ID

In my XSLT, I have the filter written out something like this:

<xsl:variable name="Rows" select="/dsQueryResponse/QuizQuestions/Rows/Row[@Quiz_x003a_ID=10]"/> 

10 in this case is just test data and I confirmed it is in the list. When I try this query, however, I get no results returned as evidenced by the following:

Count: <xsl:value-of select="count($Rows)"/>

If I take the filter out, I get every single row in the list. Now, there are two considerations which may or may not be related:

  1. In SPD, whenever I look at the Current DataSource hierarchy, it does not show an integer value for this ID field (even though it does in the SP UI). Instead it shows as "

  2. In a loop where I loop through the Rows values, , I can get and display a variable for the @Title field but cannot for the @Quiz_x003a_ID field. I get an unexpected error and correlation ID (and this is in SharePoint Online 2013) so I can't troubleshoot it further easily. This field clearly shows and I can copy the XPATH from SPD's hierarchy navigation the same.

Thanks in advance!

2

There are 2 best solutions below

1
Alex Shilman On

Try this, Im assuming you xml is similar to this:

<dsQueryResponse>
 <QuizQuestions>
    <Rows>
        <Row Quiz_x003a_ID="10">1</Row>
        <Row Quiz_x003a_ID="10">11</Row>
        <Row Quiz_x003a_ID="10">12</Row>
        <Row Quiz_x003a_ID="12">13</Row>
        <Row Quiz_x003a_ID="10">14</Row>
        <Row Quiz_x003a_ID="11">15</Row>
    </Rows>
 </QuizQuestions>
</dsQueryResponse>

And here is the XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:output method="html"/>

  <xsl:variable name="Rows" select="count(/dsQueryResponse/QuizQuestions/Rows/Row[@Quiz_x003a_ID=10])"/>
   <xsl:template match="/">
   <div>
   Count: <xsl:value-of select="$Rows"/>
   </div>
   </xsl:template>
  </xsl:stylesheet>
0
mquickel On

I believe the problem is more around the lookup fields in SP and rendering as an anchor field instead of an integer. Is there some setting for this? I saw a number of examples that seemed to suggest getting the ID should work. However, once I changed by select statement from:

/Rows/Row[@Quiz_x003a_ID=$currentQuizId]

to:

/Rows/Row[contains(@Quiz_x003a_ID,concat('&amp;ID=',$currentQuizId,'&amp;'))]

it worked as expected.