Question

I'm working with SharePoint 2007. I try to modify the DVWP with the XSLT.

The web part pulls the data from the list, what i want to do is just sort the data and show the results. - I can't sort the data directly because i need to sort / group by the field which is a choice field, so i can't.

The only viable solution for me was to modify the XSLT. Everything went good and well until I come across a problem and this problem is kind a strange.

When I use sort, it doesn't show the first value from the table! When i remove sort i have 4 (unique) values which i should have but they are not orderd, as soon as i get the sort inside the i get 3 unique values, which misses the first one. And i totaly do not understand how is it even possible.

I'll provide you pieces of XSLT which i use, as it my be an asset for helping me understand what i'm doing wrong.

To distinct the unique values i use this:

<xsl:key name="ByCategory" match="/dsQueryResponse/Rows/Row" use="@Category" />

In this subgroup (sub-template) i get this wierd behavior:

<xsl:call-template name="dvt_2.body">
<xsl:with-param name="Rows" select="$Rows" />
</xsl:call-template>


 <xsl:template name="dvt_2.body">
 <xsl:param name="Rows" />
     <td>
   <xsl:for-each select="$Rows[generate-id()=generate-id(key('ByCategory',@Category)[1])]"> 
           <xsl:sort select="@Category"/>
                     <xsl:call-template name="dvt_2.rowview">
           </xsl:call-template>
           </xsl:for-each>
 </td>
</xsl:template>

As i said before if i remove the sort, it will be ok, but unsorted, but i need sorting.

Any idea?

Thanks in advance

PS: if full xslt code is needed, i'll provide.

Was it helpful?

Solution

I found the solution and want to share with the rest, maybe it will help them in the future or those who might come across the same problem.

So the actual problem was in an if test which didn't let the first node pass:

<xsl:template name="dvt_2.rowview"> 
    <xsl:if test="(position()=1)or(@Category!= (preceding-sibling::*[1]/@Category))">   
    //xslt
    </xsl:if>   
</xsl:template>

So everytime i called it, the specifiek the second category of sorted list (or first category of unsorted list) didn't pass the if and that is why i couldn't print it out.

Removing this if test, solved the issue.

Hope this will be usefull for others

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top