1,804 articles and 14,730 comments as of Tuesday, April 12th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Tuesday, January 19, 2010

Unlocking the Mysteries of Data View Web Part XSL Tags – Part 1: Overview

Author: Marc D. Anderson
http://mdasblog.wordpress.com

Data View Web Parts (DVWPs) are, to me, the most powerful feature in SharePoint. You’ve probably heard them called the Swiss Army Knife of SharePoint and there’s really very little that you can’t display with them if you understand how they work. But understanding the inner working of DVWPs requires knowledge of some pretty crufty concepts: CAML and XSL. In this series, I hope to demystify the XSL side of things a bit by explaining the most common XSL tags you’re likely to see in DVWPs and what you can do with them.

For this first post in the series, let me list out what I see as the most common XSL tags used in DVWPs generated only by using SharePoint Designer’s dialogs. You’re liable to see most, if not all, of these tags if you switch to Split or Code view and start rummaging around in the code.  The definitions are mine, and I intend them to be simplistic, so you purists out there may need to check your vocabulary at the door!

<xsl-template>
Think of a template as a subroutine. It’s a unit of XSL to which you pass control.

<xsl:call-template>
This is how you call a template which you’ve defined with <xsl-template>.

<xsl:with-param>
You use this with <xsl:call-template> when you want to pass a value into a template, usually a value that varies.

<xsl:param>
A value you’ve passed into a template with <xsl:with-param>.  You need to have an <xsl:param> at the top of the template for each value you expect to be passed into it.

<xsl:variable>
A value you create for use within a template which is only defined within the scope of that template.

<xsl:for-each>
A way to iterate over a nodeset (group of rows).

<xsl:sort>
Used within an <xsl:for-each> to determine the sort order in which the nodeset (group of rows) are processed.

<xsl:if>
A single conditional test. If the test is true, then the contained code is executed.

<xsl:choose>
Like <xsl:if>, but with multiple possibilities, more like if-then-else.

<xsl:when>
Used within <xsl:choose> as a conditional test.  If the test is true, then the contained code is executed and the <xsl:choose> is exited.

<xsl:otherwise>
Used within <xsl:choose> as the “fall-back” condition. If none of the prior <xsl:when>s have been executed, the code contained here is executed.

<xsl:value-of>
Outputs the value to which it evaluates, whether it be the value of a column, a variable, etc.

There are more XSL tags available, but this set is what you are most likely to run into in a Data View Web Part (DVWP).  As we continue on with this series, I’ll give some examples of how you may see each of these tags used, some other interesting things you might want to do, and the results.

Author: Marc D. Anderson
http://mdasblog.wordpress.com

Marc D. Anderson is a Co-Founder and the President of Sympraxis Consulting LLC, based in Newton, MA.  He has over 25 years of experience as a technology consultant and line manager across a wide spectrum of industries and organizational sizes.  Marc has done extensive consulting on knowledge management and collaboration and what makes them actually work in practice.  Marc is a very frequent “answerer” on the MSDN SharePoint – Design and Customization forum.

Entries in this series:
  1. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 1: Overview
  2. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 2: xsl:template
  3. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 3: xsl:call-template
  4. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 4: xsl:with-param
  5. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 5: xsl:param
  6. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 6: xsl:variable
  7. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 7: xsl:for-each
  8. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 8: xsl:sort
  9. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 9: xsl:if
  10. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 10: xsl:choose
  11. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 11: xsl:value-of
  12. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 12: Miscellaneous - Person or Group Columns
  13. Unlocking the Mysteries of Data View Web Part XSL Tags - Part 13: Miscellaneous - String Functions
  14. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 14: Miscellaneous – ddwrt Namespace Functions
  15. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 15: Miscellaneous – Field / Node Functions
  16. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 16: Miscellaneous – xsl:attribute
  17. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 17: Miscellaneous – xsl:comment and xsl:text
  18. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 18: Miscellaneous – Some Math / Number Functions
  19. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 19: Miscellaneous – More Math / Number Functions
  20. Unlocking the Mysteries of Data View Web Part XSL Tags – Part 20: xsl:import
  21. EUSP eBook Store: First SharePoint Title is Now Available
 

Please Join the Discussion

21 Responses to “Unlocking the Mysteries of Data View Web Part XSL Tags – Part 1: Overview”
  1. Ron says:

    Thanks Marc.

    Looking Forward for other posts

  2. Marc,

    As we spoke offline, I’ve been very much looking forward to this series. I’m no dummy when it comes to web development technologies, but the DVWP has always sort of alluded me. I like where you’re taking this, and look forward to reading the rest of the series.

  3. Adam Carr says:

    Nice article Mark, a good solid explaination of XSL and easy to follow.

  4. Matt B. says:

    Just caught this from @TeamEUSP. It’s nice to see a clear explaination somewhere on the web. BTW, thanks for guiding me through the XSL date/time math…

  5. Jeremy Howard says:

    Thank you Marc. I look forward to the rest of the series. It has been tough to know where to start in my XSL learning. Perhaps following you is the best way sine you know how to break things down into real English for us laymen.

    Thanks again!

    - jeremy

  6. Sam Allgood says:

    crufty? What is crufty? ?8=()

  7. It’s surprising to me, but ‘crufty’ doesn’t actually seem to be a word. However, the Jargon File comes to the rescue: http://www.catb.org/jargon/html/C/crufty.html

    ;+)

    M.

  8. spevilgenius says:

    I think crufty is a newly coined technical term!

    Great article! I love what you can do with XSL!

  9. This is a must follow series, keep it up Marc

  10. Dan says:

    Great lesson, Marc! Thanks for taking the time to demystify XSL. I look forward to your future posts on this topic.

  11. Excellent Marc! Thanks for all your work about this, this is a keeper.

  12. Ajay says:

    Great Job Marc, it is excellent start for me on XSLT with DataViewWebPart.

  13. Rik Helsen says:

    We’ve just released a slideshare with an advanced/alternative approach on working with data view webparts, specifically the xslt editing part:

    http://www.slideshare.net/orbitone/share-cafe-dataviewwebparts

    Kind regards,
    Rik

  14. Get a lots of knowledge of DVWB ….
    Thanks Marc for sharing content …

Trackbacks

Check out what others are saying about this post...
  1. SharePoint Kaffeetasse 159…

    SharePoint 2010 SharePoint Designer 2010 Edit in Advanced Mode SharePoint 2010 Better Together with SQL…

  2. [...] Once that was done I need to do a few things.  I created a Web Part Page and opened SharePoint Designer.  I then added the Change Request list to one of the web part zones.  In order to get the customizations that wanted needed to create a DataView out of it so I simply right clicked on the list and converted it to a XSLT Dataview.   That’s all I really need to do here so I saved the page and opened it up in the browser.  What you can do with a dataview is almost limitless.  The best way to tackle customizations is to make all the changes you can using the SPD interface.  Once you have reached the limits of what you can do there you can start customizing the XSL.  Refer to the following series by Marc to learn everything you need to know about XSL and the DVWP.  http://www.endusersharepoint.com/2010/01/19/unlocking-the-mysteries-of-data-view-web-part-xsl-tags-p… [...]

  3. [...] can utilize XSLT functions to extract the email address.  Marc Anderson has a great series on mastering the Data view web part.  In this scenario we will be working with 2 string functions, substring-before and [...]

  4. [...] Yes, this is squarely advanced XSLT editing. Need help? See Marc Anderson’s excellent EUSP series Unlocking the Mysteries of Data View Web Part XSL Tags. [...]

  5. Essential Links for the SharePoint Client Side Developer…

    Front End Developer? Client Side Developer? Middle Tier??? I’m covering all my bases. Regardless, I’m…




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!