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.
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 1: Overview
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 2: xsl:template
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 3: xsl:call-template
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 4: xsl:with-param
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 5: xsl:param
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 6: xsl:variable
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 7: xsl:for-each
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 8: xsl:sort
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 9: xsl:if
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 10: xsl:choose
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 11: xsl:value-of
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 12: Miscellaneous - Person or Group Columns
- Unlocking the Mysteries of Data View Web Part XSL Tags - Part 13: Miscellaneous - String Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 14: Miscellaneous – ddwrt Namespace Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 15: Miscellaneous – Field / Node Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 16: Miscellaneous – xsl:attribute
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 17: Miscellaneous – xsl:comment and xsl:text
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 18: Miscellaneous – Some Math / Number Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 19: Miscellaneous – More Math / Number Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 20: xsl:import
- EUSP eBook Store: First SharePoint Title is Now Available
Thanks Marc.
Looking Forward for other posts
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.
Nice article Mark, a good solid explaination of XSL and easy to follow.
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…
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
crufty? What is crufty? ?8=()
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.
I think crufty is a newly coined technical term!
Great article! I love what you can do with XSL!
This is a must follow series, keep it up Marc
Great lesson, Marc! Thanks for taking the time to demystify XSL. I look forward to your future posts on this topic.
Excellent Marc! Thanks for all your work about this, this is a keeper.
Great Job Marc, it is excellent start for me on XSLT with DataViewWebPart.
Ajay:
Buy the eBook and get all of the articles in one convenient PDF! :+)
M.
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
Get a lots of knowledge of DVWB ….
Thanks Marc for sharing content …
You’re welcome, Pritesh!
M.