Extending Sharepoint XSL template - sharepoint

Thanks to this post I've come up with the following template:-
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink1"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')" />
</a>
This template is nested in an unorderd list and li tag (see below). Since this code has a physical and visual presence in the html page when no content exists I would like to add the li tags and possibly the ul tags to the template. Can anyone tell me how to accomplish this?
<ul>
<li>
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink1"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')"/>
</a>
</li>
<li>
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink2"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')"/>
</a>
</li>
<li>
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink3"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')"/>
</a>
</li>

I'm assuming from your link to the other post that you are using the Content Query Web Part here.
You need to wrap your call to this variable using XSLT header/footer techniques. Here is one of a few posts I've seen that show how this can be done with the CQWP in particular.

You could try using the xsl:if elements to conditionally output content. You can find more info on how xsl:if works # http://www.w3schools.com/xsl/xsl_if.asp or just use your favorite search engine.

Related

How to get the value of the currently matched xsl node into a variable?

In my xsl, I want to match on several nodes and then grab the value of the matched node into a variable. How can I do that?
I need to place a wildcard variable in place of Budget0 below:
<xsl:template match="FieldRef[#Name='Budget0' or #Name='Scope' or #Name='Risk' or #Name='Schedule']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/Budget0" />
<xsl:variable name="statusRating1">(1)</xsl:variable>
<xsl:variable name="statusRating2">(2)</xsl:variable>
<xsl:variable name="statusRating3">(3)</xsl:variable>
<xsl:choose>
<xsl:when test="contains($currentValue, $statusRating1)">
<span class="statusRatingX statusRating1"></span>
</xsl:when>
<xsl:when test="contains($currentValue, $statusRating2)">
<span class="statusRatingX statusRating2"></span>
</xsl:when>
<xsl:when test="contains($currentValue, $statusRating3)">
<span class="statusRatingX statusRating3"></span>
</xsl:when>
<xsl:otherwise>
<span class="statusRatingN"><xsl:value-of select="$currentValue" /></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
In this snippet, the xsl:template match... works just fine; it does seem to match those fields. I can see in Firebug that those fields receive the statusRating1 css class just like they should (since they are all set to receive the value of the Budget0 field.
[update]
I found that if I use this for the variable:
<xsl:variable name="currentValue" select="current()/#Name" />
or
<xsl:variable name="currentValue" select="FieldRef[#Name=current()/#Name"] />
It will get caught in the otherwise tag, and will print the name of the field. In other words, the html prints
<span class="statusRatingN">Budget0</span>
If I try any of Dimitre's solutions (below), it never matches in any of the when clauses, and the html is outputted like this (notice the span's text is blank):
<span class="statusRatingN"></span>
Therefore, I deduce that the $currentValue is only getting the name of the attribute, it isn't referring to value of the node. I need to refer to the value of that particular node.
Use:
<xsl:variable name="currentValue" select="$thisNode/*[name()=current()/#Name]"/>
Or, alternatively:
<xsl:variable name="currentValue" select="$thisNode/*[name()=$thisNode/#Name]"/>
Or, alternatively (best):
<xsl:variable name="currentValue" select="*[name()=current()/#Name]"/>
Ah, after hours and hours and hours and days and months, here is an example (which I fiddled myself with help from this thread):
These two lines are the keys (Dimitre's answer was close):
<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/#*[name()=current()/#Name]" />
Here is the entire function, which reads two different columns and applies the values to either one:
<xsl:template match="FieldRef[#Name='YesNo1']|FieldRef[#Name='YesNo2']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/#*[name()=current()/#Name]" />
<xsl:variable name="yesvalue">Yes</xsl:variable>
<xsl:variable name="novalue">No</xsl:variable>
<xsl:choose>
<xsl:when test="contains($currentValue, $yesvalue)">
<span class="yesno yes"><xsl:value-of select="$currentValue" /></span>
</xsl:when>
<xsl:when test="contains($currentValue, $novalue)">
<span class="yesno no"><xsl:value-of select="$currentValue" /></span>
</xsl:when>
<xsl:otherwise>
<span class="yesnoN"><xsl:value-of select="$currentValue" /></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

SharePoint 2010: How do I use the 'onmouseover' attribute in the ItemStyle.XSL file for the Content Query Webpart?

I'm currently working in SharePoint 2010, with the Content Query Webpart.
I just want to show a list, but when the user hovers the mouse over the item, I want him/her to see a description. I have tried to put the 'onmouseover' attribute everywhere, but nothing seems to work.
This is my code so far:
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Description">
<xsl:value-of select="#Description" />
</xsl:variable>
<xsl:variable name="Start">
<xsl:value-of select="ddwrt:FormatDateTime(string(#Start), 1033, 'H:mm')" />
</xsl:variable>
<xsl:variable name="End">
<xsl:value-of select="ddwrt:FormatDateTime(string(#End), 1033, 'H:mm')" />
</xsl:variable>
<xsl:variable name="Speaker">
<xsl:value-of select="#Speaker" />
</xsl:variable>
<xsl:variable name="tableStart">
<xsl:if test="$CurPos = 1">
<![CDATA[
<table border=1 bgcolor=#CCFFFF>
<tr>
<td><b>Start</b></td>
<td><b>End</b></td>
<td><b>Title</b></td>
<td><b>Speaker</b></td>
</tr>
]]>
</xsl:if>
</xsl:variable>
<xsl:variable name="tableEnd">
<xsl:if test="$CurPos = $Last">
<![CDATA[ </table> ]]>
</xsl:if>
</xsl:variable>
<xsl:comment>Start of HTML section</xsl:comment>
<xsl:value-of select="$tableStart" disable-output-escaping="yes"/>
<tr>
<td><b> <xsl:value-of select="$Start"/> </b></td>
<td><b> <xsl:value-of select="$End"/> </b></td>
<td style="width:500px"><b> <xsl:value-of select="$DisplayTitle"/></b></td>
<td> <xsl:attribute name="onmouseover"> <xsl:value-of select="#Description"/> </xsl:attribute> </td>
<td><b> <xsl:value-of select="$Speaker"/> </b></td>
</tr>
<xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>
Where do I put the 'onmouseover' attribute so that when your mouse hovers over an item, it shows the description?
Thanks in advance.

MOSS Content Query Web part itemstyle.xsl

I have a Content Query Webpart (CQWP) pulling the URL and title from a News links list. The CQWP uses the XSLT style Orange.News.Links defined in ItemStyle.xsl.
I need to sort the title #Title0 field as commented out below because it causes an error.
Does anyone know whats causing this error? - Many Thanks. The XSLT code is below:
<xsl:template name="Orange.News.Links" match="Row[#Style='Orange.News.Links']" mode="itemstyle">
<xsl:param name="CurPos" />
<xsl:param name="Last" />
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#URL"/>
<xsl:with-param name="UrlColumnName" select="'URL'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="LinkTarget">
<xsl:if test="#OpenInNewWindow = 'True'" >_blank</xsl:if>
</xsl:variable>
<xsl:variable name="SafeImageUrl">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Header">
<xsl:if test="$CurPos = 1">
<![CDATA[<ul class="list_Links">]]>
</xsl:if>
</xsl:variable>
<xsl:variable name="Footer">
<xsl:if test="$Last = $CurPos">
<![CDATA[</ul>]]>
</xsl:if>
</xsl:variable>
<xsl:value-of select="$Header" disable-output-escaping="yes" />
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="substring-before($DisplayTitle,', ')"></xsl:value-of>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="#Description"/>
</xsl:attribute>
<!-- <xsl:sort select="#Title0"/> -->
<xsl:value-of select="#Title0">
</xsl:value-of>
</a>
</li>
<xsl:value-of select="$Footer" disable-output-escaping="yes" />
</xsl:template>
I need to sort the title #Title0 field
as commented out below because it
causes an error.
Does anyone know whats causing this
error?
Yes, <xsl:sort/> can only be a child node of either <xsl:apply-templates> or <xsl:for-each> (and of <xsl:perform-sort> in XSLT 2.0).
Recommendation: Take at least a mini-course in XSLT and XPath so that you at least grok the fundamental concepts.

SharePoint XSLT Problem -

I am trying to do some highlighting on some SharePoint XSLT Results. BElow is the XML that i am getting.
The Problem that i am getting is that the Template Match blocks are not matching the child nodes of UM If someone can see where i am going wrong that woould be great.
Thank you
Chhris
<rows>
<row>
<LastModifiedTime>02/25/2010 18:32:25</LastModifiedTime>
<RANK>325</RANK>
<TITLE>UMUK Win At The Mobile Entertainment</TITLE>
<AUTHOR>SVR08-002\Administrator</AUTHOR>
<CREATED>02/25/2010 18:32:22</CREATED>
<PATH>http://svr08-002:7005/Lists/FrontPageNews/DispForm.aspx?ID=3</PATH>
<HitHighlightedSummary>a
<c0>UM</c0> UK won the category of Best Music Label 2009 at the 4th annual ME (Mobile Entertainment) Awards C <ddd/>
</HitHighlightedSummary>
</row>
</rows>
and here is the XSLT that i have so far.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<table class="ICS_SearchTable" cellpadding="0" cellspacing="0" width="100%">
<xsl:for-each select="rows/row">
<xsl:variable name="Ext">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="substring-before(PATH, '?')" />
</xsl:call-template>
</xsl:variable>
<tr>
<td width="10%">
</td>
<td>
<div class="ICS_SearchResultItem">
<div class="ICS_SearchResultItemImage">
<img src="/Style Library/UMIGlobe/Styles/Images/Common/umgi-{$Ext}.png" alt="{$Ext}"/>
</div>
<div class="ICS_SearchResultItemTitle">
<xsl:value-of select="TITLE"/>
</div>
<div class="ICS_SearchResultItemDesc">
<xsl:choose>
<xsl:when test="HitHighlightedSummary[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="HitHighlightedSummary" />
</xsl:call-template>
</xsl:when>
<xsl:when test="DESCRIPTION[. != '']">
<xsl:value-of select="DESCRIPTION"/>
</xsl:when>
</xsl:choose>
</div>
<div class="ICS_SearchResultItemLink">
<xsl:value-of select="PATH"/> - <xsl:value-of select="AUTHOR" /> - <xsl:value-of select="LastModifiedTime"/>
<xsl:call-template name="DisplaySize">
<xsl:with-param name="size" select="SIZE" />
</xsl:call-template>
</div>
</div>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="HitHighlighting">
<xsl:param name="hh" />
<xsl:apply-templates select="$hh"/>
</xsl:template>
<xsl:template match="ddd">
…
</xsl:template>
<xsl:template match="c0">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c1">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c2">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c3">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c4">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c5">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c6">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c7">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c8">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c9">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<!-- The size attribute for each result is prepared here -->
<xsl:template name="DisplaySize">
<xsl:param name="size" />
<xsl:if test='string-length($size) > 0'>
<xsl:if test="number($size) > 0">
-
<xsl:choose>
<xsl:when test="round($size div 1024) < 1"><xsl:value-of select="$size" /> Bytes</xsl:when>
<xsl:when test="round($size div (1024 *1024)) < 1"><xsl:value-of select="round($size div 1024)" />KB</xsl:when>
<xsl:otherwise><xsl:value-of select="round($size div (1024 * 1024))"/>MB</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="get-file-extension">
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="contains( $path, '/' )">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="substring-after( $path, '/' )" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains( $path, '.' )">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="substring-after( $path, '.' )" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- SET THE PATH IMAGE SRC -->
<xsl:choose>
<xsl:when test="$path = 'uk' or $path = 'org' or $path = 'com' or $path = 'net' or $path = 'biz' or $path = 'gov'">
<xsl:text>url</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
What do you mean by "child nodes of UM"?
Maybe I'm missing something, but there are no nodes named "UM", just text. So do you mean that you want to match the node that contains the text "UM"... in other words <c0>UM</c0>?
In my case, when I run your stylesheet, it does match the <c0> node, and writes a <b> node.
<b>UM</b> UK won the category of Best Music Label 2009 at the 4th annual ME (Mobile Entertainment) Awards C
What's not working for you?

How to add a link to the rest of the paragraph in SharePoint Announcements?

How can I create a link to the rest of the paragraph in an announcement in SharePoint, that displays the word: read more
Cheers
I've found that the cleanest, easiest way to do this is to create a template in ItemStyle.xsl which selects a substring of the body content of the announcement and displays a link below to the article itself.
After adding the following code to your ItemStyle.xsl file (in SharePoint Designer navigate to the 'Style Library/XSL Style Sheets' folder), you can modify the web part through the browser, and change the Item Style (Presentation/Styles) to 'ReadMoreAnnouncements'. This code keeps the amount of characters displayed to 190 characters (see the substring($bodyContent,1,190 function call).
<xsl:template name="removeMarkup">
<xsl:param name="string" />
<xsl:choose>
<xsl:when test="contains($string, '<')">
<xsl:variable name="nextString">
<xsl:call-template name="removeMarkup">
<xsl:with-param name="string" select="substring-after($string, '>')" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(substring-before($string, '<'), $nextString)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="ReadMoreAnnouncements" match="Row[#Style='ReadMoreAnnouncements']" mode="itemstyle">
<br />
<div class="RMAnnouncementsTitle">
<xsl:value-of select="#Title" />
</div>
<div class="RMAnnouncementsBody">
<xsl:variable name="bodyContent">
<xsl:call-template name="removeMarkup">
<xsl:with-param name="string" select="#Body"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring($bodyContent,1,190)" />
...
<br />
<a>
<xsl:attribute name="href">
/Lists/Announcements/DispForm.aspx?ID=
<xsl:value-of select="#ID">
</xsl:value-of>
</xsl:attribute>
<xsl:attribute name="class">
RMAnnouncementsMoreLink
</xsl:attribute>
read more
</a>
</div>
</xsl:template>
This should definitely work, and it's very very easy to implement.
If you have a page and can edit it in SharePoint Designer, try this.
If you want to have a web part that shows the announcement the way you want, try this.

Resources