xsltsharepointsharepoint-2013sharepoint-designer

How to get the first file from multiple folders in a document library in SharePoint Designer 2013


I have a document library built in SharePoint. Inside this library there are multiple Document Set folders that contain template documents. I want to create a view where it only shows the most recent document from each of those folders. The reasoning is to have a library maintainer be able to drop a new file inside of it's designated folder and the users will be able to see a view with the list of the most recent documents from each folder without needing to click into the library and check each folder to see if a new file was uploaded.

Creating a view on SharePoint directly on the website does not satisfy this requirement for displaying the documents as outlined above. I have looked into a Content Query Web Part, but this feature also does not have enough settings to make this feature work. I opted to using SharePoint Designer 2013 and created a Custom Web Part and got stuck trying to edit the view. Through SharePoint Designer, I've managed to sort the records by their Modification date which puts the most up to date document at the top of the list. Then I managed to group the records by the folder name or "type of template". Now I am stuck trying to parse through the XSLT generated source code by SharePoint Designer and figuring out a way how to only display the first record of each folder/group. I currently have a REST call approach using jQuery and it seems to work fine, but I am trying to find if there is an XSLT approach that can solve this problem.

Update - Adding XML snippet

Here is a snippet of the XML that resembles the library.

<Library>
  <Template>
    <FileName>ExpensesReport.xslx</FileName>
    <ModifiedDate>2022-12-10</ModifiedDate>
    <TemplateType>Excel</TemplateType>
  </Template>
  <Template>
    <FileName>Presentation.ppt</FileName>
    <ModifiedDate>2022-12-11</ModifiedDate>
    <TemplateType>PowerPoint</TemplateType>
  </Template>
</Library>

Solution

  • I managed to figure out the solution at the end. I found this resource, get first item from each group. I used one of the solutions provided and incorporated it to my problem.

    test="not(templateType = preceding::Row/@templateType)"
    

    Using SharePoint Designer, I used the filter icon to add this condition: @fileType != 'not null'. I also added the formula into this section:

    <xsl:with-param name="Rows" select=$Rows[not(templateType = preceding::Row/@templateType)]
    

    With these changes, the view only displays the first file from each template folder.