Customizations
My favorite XSL tips / tricks
I’m compiling a list of my favorite XSL tip and tricks that always help me. These items are not going to be in any particular order
1) Linking Javascript or CSS
1 2 3 4 5 6 |
<xsl:text disable-output-escaping="yes"> <![CDATA[ <link rel="stylesheet" href="/Style Library/myCss.css"/> <script type="text/javascript" src="/Style Library/js/myScript.js"></script> ]]> </xsl:text> |
2) Stripping HTML
the first section is the how to call the template below it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<!-- calling template --> <xsl:call-template name="remove-html"> <xsl:with-param name="text" select="@MyText"> </xsl:call-template> <!-- template --> <xsl:template name="remove-html"> <xsl:param name="text"/> <xsl:choose> <xsl:when test="contains($text, '<')"> <xsl:value-of select="normalize-space(substring-before($text, '<'))"/> <xsl:text> </xsl:text> <xsl:call-template name="remove-html"> <xsl:with-param name="text" select="normalize-space(substring-after($text, '>'))"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="normalize-space($text)"/> </xsl:otherwise> </xsl:choose> </xsl:template> |
3) Trim String
1 2 3 4 5 6 7 8 |
<xsl:choose> <xsl:when test="string-length(@MyString) > 50"> <xsl:value-of select="substring(@MyString, 1, 49)" />... </xsl:when> <xsl:otherwise> <xsl:value-of select="@MyString" /> </xsl:otherwise> </xsl:choose> |
4) Show all XML output
1 2 3 4 5 6 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <xmp><xsl:copy-of select="*"/></xmp> </xsl:template> </xsl:stylesheet> |
5) SharePoint Templates
A nice set of pre-built .xsl templates for use which contains some helpful things.