xsltsharepoint-2010groupingxslt-1.0dataviewwebpart

sharepoint dataview webpart xslt group by left characters of a column


I have a sharepoint 2010 list with a column "proposalID". The values in that column are 5555-01, 5555-02, 5555-03, 6666-01, 6666-02, etc.

I want to group by the 4 characters to the left of the dash. So the grouping would display 3 items under 5555 and 2 items under the group 6666, etc.

Using Sharepoint Designer 2010, I added a blank dataview webpart, connected to my list, and from the ribbon chose to sort by the Proposal ID column. It rendered the below xsl ddwrt code:

I've been trying various syntax to change the string function but have not been successful. I tried to glean some knowledge from this posting, http://jamestsai.net/Blog/post/SharePoint-Data-View-Data-Form-Web-Part-Group-items-by-month-on-DateTime-field.aspx - but was not able to apply the string syntax to my case.

Could someone suggest how I can accomplish this grouping? Thank you in advance.

<xsl:choose>
  <xsl:when test="not ($dvt_groupfield)">
    <xsl:value-of select="ddwrt:NameChanged(string(@ProposalID), 0)" />
  </xsl:when>
  <xsl:otherwise></xsl:otherwise>
</xsl:choose>

Solution

  • Based on that blog post, I would presume that the following would work in this case:

    <xsl:choose>
      <xsl:when test="not ($dvt_groupfield)">
        <xsl:value-of select="ddwrt:NameChanged(string(substring(@ProposalID, 1, 4)), 0)" />
      </xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
    

    using 1 and 4 as the bounds for the substring.

    And similarly for the title, also as indicated in the blog post:

    <xsl:when test="not (@ProposalID) and (@ProposalID) != false()">
      <xsl:value-of select="' '" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="substring(@ProposalID,1,4)" />
    

    Could you give that a try?