Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In a publishing site, I want to create a webpart that display the result of a query with a custom display (a kind of rotator).

As the goal of the web part is to be reusable and must be quite simply configurable by the user, I'm wondering what are the pros and cons of the following approaches :

  • custom web part that produces the html in a "hard-coded" way. Add tool pane to allow the user to setup data
  • content query web part with a xslt transformation
  • silverlight web part with a custom option pane within the webpart

I feel the 2nd solution may be better because the whole setup of the webpart is already here, but I fear a bit the xslt will be quite painful.

thanks in advance for your feedbacks

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

Don't be afraid of XSLT. This is going to give you a tremendous amount of power without having to develop or deploy anything in return for a little effort to understand it. I always recommend starting with an identity transform so that you can see the XML that is coming in, and then start adding templates to process the nodes you are interested in.

Visual Studio has great tooling for working with XSLT. You can create an intitial XSLT with an identity transform and then use it to transform a source XML file (corresponding to your list data). You can then start the transformation in debug mode and breakpoint and step through your XSLT.

Having said that, there are cases where writing a custom web part makes sense. There may be something you need that CQWP can't do, or the CQWP solution may be very convoluted in some cases. That's something you have to decide from understanding the problem. But don't avoid CQWP because of XSLT.

share|improve this answer
1  
+1. However, if you need to iterate over Site Collections, the CQWP will not do. –  tarjeieo Jun 2 '11 at 16:38
    
+1 for don't fear the XSLT. There's plenty of us out there who'll happily help you out and point you to resources to further your knowledge. –  James Love Jun 2 '11 at 16:48
add comment

For your case, i.e. displaying results with custom display, i would recommend two options:

  1. Transform results on client side, for example if you use some kind of jQuery plugin for Rotator, it would be possible to initialize results data for Rotator with jQuery.
  2. The option with extending the CQWP, in that case you could customize the rendering of results, for example see my blog Rendering Content Query Web Part results in Table Layout about how to arrange items in Plain Old Table Layout instead of List Layout
share|improve this answer
add comment

Another option, expanding on Bill(SPDoctor)'s answer, is to extend the CQWP, by creating a new class for your web part that inherits from ContentByQueryWebPart.

This will let you add more options to the toolpane to control the logic, as well as make custom methods available in your XSLT, which you can write "code-behind" for in your webpart's class.

Waldek Mastykarz has covered this in a series of excellent blog posts on this site: http://blog.mastykarz.nl/extending-content-query-web-part-with-custom-data/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.