1,739 articles and 13,478 comments as of Sunday, October 24th, 2010

Tuesday, March 23, 2010

Unlocking the Mysteries of Data View Web Part XSL Tags – Part 17: Miscellaneous – xsl:comment and xsl:text

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

There are a few more XSL tags that I should briefly touch upon. They are used much less often than the others that I’ve covered, but more than the bunch that I’m not going to talk about at all. There’s a set of them that are really only going to make sense to hard-code XSL junkies. I’m going to assume that readers of EndUserSharePoint.com don’t typically fall into this category.

<xsl:comment>

This one should be pretty obvious. With <xsl:comment>, you can insert comments into your XSL. (Did you guess right?) You can include any valid text within the <xsl:comment> tags.

There’s a big caveat with this, however, and it’s probably the main reason why you don’t see a lot of comments in Data View Web Part (DVWP) XSL. When you make changes using the Common Data View Tasks (the dialogs), SharePoint Designer can tend to move your comments around. That means that the really great comment you wanted to put into your XSL (like <xsl:comment>The next line does X.</xsl:comment>) may end up in a completely different part of the XSL. (As I’ve mentioned before, SharePoint Designer is really a code-generator.)

<xsl:text>

At least a few of the XSL tags have names that make sense, right? <xsl:text> lets you output text. The nice thing is the by enclosing the text in the <xsl:text> tags, you’re basically saying “Don’t mess with this”. You also have the option, like with <xsl:value-of>, to include the disable-output-escaping="yes" attribute. This allows you to include HTML markup.

Here are a few examples:

<xsl:text>blah blah blah</xsl:text>
<xsl:text disable-output-escaping="yes"><a href="http://blah">blah blah blah</a></xsl:text>

Generally, you can achieve the same effect with <xsl:value-of> by enclosing the value in single quotes in the select attribute:

<xsl:value-of select="'blah blah blah'"/>

No, I’m not quite done with this series yet, but I do think that I’ve covered all of the XSL tags that will be of general interest. If there are any which you were waiting breathlessly for, ping me and I’ll add them later. The next installment will cover a few ddwrt: functions which I’ve never been able to figure out. Nothing sensical on the Web, no documentation, just fun stuff all around.

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

5 Responses to “Unlocking the Mysteries of Data View Web Part XSL Tags – Part 17: Miscellaneous – xsl:comment and xsl:text”
  1. paisleygo says:

    RE: – why does spd insist on wrapping every space ( ) in one of those when you use the design view to add a space?
    how do you handle spaces?

    • paisleygo:

      I think you probably posted some code above, but it doesn’t come through in Wordpress comments. Can you explain your question a bit more? In the emailed alert that I got, I did see the

      &nbsp;

      escaped character. This is a non-breaking space. What this tells the browser is not to wrap or otherwise “nreak” the line at this position.

      M.

  2. paisleygo says:

    If I add a sopace in the design view – spd adds a looooooooong line of xsl that is something like
    xsl:text xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime” ddwrt:whitespace-preserve=”yes” xml:space=”preserve” /xsl:text

    I am wondering if there is a shorter way of saying that – in the xml – and if there is a way to set a prefernce in spd to not mark it up that way

  3. paisleygo says:

    Oh and BTW!!!!

    Thank you soooooooo much for this series – It has really helped me start to make sense of the code and feel more confident of getting things to work the way I want them and not have to depend on the wizards so much

    I look forward to learning more youre writing style is very clear
    Thanks!!!!!!!

  4. Glad you are finding the series helpful! If you’d like to have a full copy around for reference, consider buying the eBook version.

    SPD is adding that xsl:text tag to “protect” the space from other things you migth be doing. Once you get more familiar with XSL, you may find more concide ways to do what you want. For instance, if you simply wanted to always have a space after the value of @ColumnName, you can do

    <xsl:value-of select="concat(@ColumnName, ' ')"/>

    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!