Part 1. Build your own data source for Data Form Web Part
Part 2. Use XSLT generated from SharePoint Designer to display data
In last post I have described how to build a data source and use it in custom DataFormWebPart to query cross-site lists.
Now, I am going to explain how you can display result data easily by using XSLT from SharePoint Designer.
Like I have mentioned in previous post, you should build data result in specific format. The format respects the XSLT that will be generated by SharePoint Designer. The format looks like this
<dsQueryResponse>
<Rows>
<Row Attribute1="" Attribute2="" Attribute3=""/>
<Row Attribute1="" Attribute2="" Attribute3=""/>
</Rows>
</dsQueryResponse>
Atrribute 1,2,3 can be field name.
1. Create a new page with DataFormWebPart
Once you have data present in above format. You can then go into SharePoint Designer and open the library/list that your cross-site query will be queried on. And create a new temporary .aspx page in this library.
In our case, this page can be created in any sub-site's page library.
After you created a new page, insert a data view (DataFormWebPart) control to this page.
And select a data source from the data source panel for this control
In this example we select "Pages" library as our data source. Because we want to use the site columns for the content type used in this page library as display fields. (Same fields we queried in result data in Part 1.)
Surely You can create this temporary .aspx page in any place you like. But create it under right site avoid extra works for set up data source library manually. To get site columns you want.
2. Customise the presentation of DataFormWebPart
Now, you can select all the fields you wanted to display in your cross-site lists DataFormWebPart. And insert them to the control.
Sample data view will be displayed on the page for you to preview the result.
3. Copy XSLT
If everything looks good to you, right click on the DataFormWebPart on the page and select "Web Part Properties..".
In XSL Editor box, copy the XSLT and save it to separate file for your custom cross-list DataFormWebPart to use.
[code:c#]
//XSLT saved in CrossList.xsl and use it via code.
//XslLink can also be set from Web Part Properties UI
CustomDataFormWebPart dfwp = new CustomDataFormWebPart();
dfwp.XslLink = "/Style Library/XSL Style Sheets/CrossList.xslt"
[/code]
Now, You should be able to display data without any changes to this XSLT. Because display fields matches attributes of our result XML data.
At this stage you have both custom cross-site DataFormWebPart control and XSLT presentation file.
Note
If you changed the display layout in Step 2 to enable Sorting and Filtering on column headers. You may find filtering does not work properly. It returns no data for you to perform filtering when you click on column headers.
It is because the default implementation of the method (the one return filtering data) in DataFormWebPart class does not support our custom data source.
Coming up..
In Part 3. I will post about how to get filtering to work on column headers!