SharePoint - Content Query Web Part: Lookup Column Value and XSL - sharepoint

There is a List with Lookup field. And there is a CQWP web part which uses this list as a Source and uses custom XSL style added to Itemstyle.xsl.
And there is a problem how to render this field as a link?
Field name is 'Category' and
<xsl:value-of select="#Category" />
Returns a string with item's title (like 'Some Category'). But I need a URL or ID. Any suggestions?

Try something like this :
<a>
<xsl:attribute name="href">
<xsl:value-of select="#Url" />
</xsl:attribute>
<xsl:value-of select="#Category" />
</a>

Use disable-output-escaping, for example:
{less than symbol}xsl:value-of disable-output-escaping="yes" select="#Category" /{greater than symbol}

Related

XSL to Excel: Choose not processing formula

I declared a variable with a simple Excel formula (not the formula I will eventually use, just something simple for testing)
<xsl:variable name="nistcci" ss:Formula="=RC19"></xsl:variable>
Then I am trying to use a Choose to determine if the attribute data is empty, then return based on that determination.
<Cell ss:StyleID="stig_rules"> <!-- IA Control(s) -->
<Data ss:Type="String">
<xsl:choose>
<xsl:when test="STIG_DATA/VULN_ATTRIBUTE[node()='IA_Controls']/../ATTRIBUTE_DATA != ''">
<xsl:value-of select="STIG_DATA/VULN_ATTRIBUTE[node()='IA_Controls']/../ATTRIBUTE_DATA" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$nistcci"/>
</xsl:otherwise>
</xsl:choose>
</Data>
This works if I do something simple like:
<xsl:variable name="nistcci">sean</xsl:variable>
But isn't working with a formula within a referenced variable.
Thanks for the help. Sean.
It's not clear what you want your variable to contain.
It is quite clear that the xsl:variable instruction cannot have a ss:Formula attribute, or any other attribute except select and (in XSLT 2.0) as.
Your variable needs to be constructed as:
<xsl:variable name="myVar" select="myExpr"/>
where myExpr must be a valid XPath expression.
Alternatively, you could use something like:
<xsl:variable name="myVar">
<xsl:attribute name="ss:Formula">=RC19</xsl:attribute>
</xsl:variable>
to construct a variable that holds an attribute.

Fix XSLT Numeric Cell Output to Excel as String

I am using an XSLT template to convert and format some output from FileMaker to Excel. It works perfectly for all but one column. The data is numeric, but must be output as a string in the format NN.NN. The data field is entered as, for example, 04.13, but when output to Excel, displays as 4.13. There are some cases where the user has input 04 13 (which oututs correctly as it cannot be parsed as a number) but where the user has entered the data correctly into filemaker (the field is Text), i.e. 04.13, I need to ensure the output data remains in the correct format.
I have tried the following, but it does not appear to work as expected - the output file still shows the column values as numbers, ie loses the leading zero:
<xsl:choose>
<xsl:when test="$xlFieldName='d_Oracle_Task_Code'">
<xsl:variable name="OracleTaskCode" select="fmp:DATA" />
<xsl:value-of select='format-number(OracleTaskCode, "00.00")' />
</xsl:when>
</xsl:choose>
I'm not worried about the cases where the input is missing the decimal point seperator, only ensuring the values are output as text.
Try defining a variable as:
<xsl:variable name="apos">'</xsl:variable>
then use:
<xsl:value-of select="concat($apos, format-number(OracleTaskCode, '00.00'))" />
Another option worth trying would be to define the cell contents as data type string:
<Data ss:Type="String">
....
</Data>
I am afraid I have no means to test either.
My issue was the order in which I checked. I could not get the XSLT to apply the formatting or append the apostrophe until I made my when block the first one in my choose block.
<Style ss:ID="xlTextStyle">
<NumberFormat ss:Format="#"/>
</Style>
<xsl:choose>
<xsl:when test="$xlFieldName='d_Scheme_Task_Code'">
<xsl:attribute name="ss:StyleID">xlTextStyle</xsl:attribute>
<Data>
<xsl:attribute name="ss:Type">String</xsl:attribute>
<xsl:value-of select="." />
</Data>
</xsl:when>
<xsl:when test="$xlFieldType='NUMBER'">
<xsl:choose>
<xsl:when test...
I'm now getting the column values correctly formatted using the Text format.

XSL / XSLT - Adding a value-of as a style attribute for a DIV

I'm using SharePoint 2010 and the Content Query Web Part to output a list of dates from a SharePoint list. The display of this list is controlled by an XSL stylesheet called ItemStyle.xsl
I have made progress with the general appearance but would now like to add one of the fields it retrieves as a background/style attribute.
I believe the problem I am having relates to the xsl value-of select having a closing bracket at the end of the tag and therefore inadvertently closing my DIV. Can someone look at the code below and suggest alternative way of printing the CategoryColour within the opening DIV.
I also will occasional have "xmlns:ddwrt" inserted into the html where I would expect to at least see "style:background...."
Many Thanks
<xsl:stylesheet
version="1.0"
exclude-result-prefixes="x d xsl msxsl cmswrt"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<!-- PrettyCal Template -->
<xsl:template name="PrettyCal" match="Row[#Style='PrettyCal']" mode="itemstyle">
<xsl:variable name="Start"><xsl:value-of select="#EventDate" /></xsl:variable>
<xsl:variable name="End"><xsl:value-of select="#EndDate" /></xsl:variable>
<xsl:variable name="AllDay"><xsl:value-of select="#AllDayEvent" /></xsl:variable>
<xsl:variable name="Location"><xsl:value-of select="#EventLocation" /></xsl:variable>
<xsl:variable name="CategoryColour"><xsl:value-of select="#EventCategoryColour" /></xsl:variable>
<div class="upcoming-events" style="background: {CategoryColour}" ><xsl:value-of select="$CategoryColour"/>
<h2 class="event-title">
<a>
<xsl:attribute name="onClick">
javascript:SP.UI.ModalDialog.showModalDialog({ url: '/services/marketing/Lists/College%20Calendar/DispForm.aspx?ID=<xsl:value-of select="#ID" />', title: 'Event Details' }); return false;
</xsl:attribute>
<xsl:value-of select="#Title" /></a></h2>
</div>
</xsl:template>
</xsl:stylesheet>
You have:
<div class="upcoming-events" style="background: {CategoryColour}" ><xsl:value-of select="$CategoryColour"/>
You actually wanted:
<div class="upcoming-events" style="background: {$CategoryColour}" ><xsl:value-of select="$CategoryColour"/>
Your missing a $ in front of the variable CategoryColour.

Sharepoint XSL - break string into componant parts

I'm using a "choice" site column with the multiple-check option enabled so that users can tag a list item with several choices from the column.
This column then powers a design feature in a content query webpart - where the column choice is appended to create an image filename.
Choice1
Choice2
Choice3
Choice4
becomes
<img src="http://mysite/content-Choice1.jpg />
The problem I've got is that the XSL parser is fed a string which has semicolons (;) and hashes (#) separating the choice values. If all 4 options were ticked, the string fed into the XSLT parser would be:
;#Choice1;#Choice2;#Choice3;#Choice4
How can I work through the string and separate each choice into its own XSL variable?
I've tried various substring-before functions, but I can't get anything working.
Since XPath 1.0 does not support the tokenize() function, you'll have to do all the work yourself. For instance, you can generate the <img> elements recursively from the choices:
<xsl:template name="RecurseConvertChoicesToImages">
<xsl:param name="choices" />
<xsl:variable name="token"
select="substring-before($choices, ';#')" />
<xsl:variable name="nextToken"
select="substring-after($choices, ';#')" />
<xsl:if test="$token">
<img src="http://mysite/content-{$token}.jpg" />
</xsl:if>
<xsl:if test="$nextToken">
<xsl:call-template name="RecurseConvertChoicesToImages">
<xsl:with-param name="choices" select="$nextToken" />
</xsl:call-template>
</xsl:if>
</xsl:template>
I would recommend to use JavaScript to parse the string and accordingly display the image using JavaScript.

Outputting SharePoint Hyperlink Column as URL

I have some document URLs stored in a Sharepoint publishing column. When I output the info into a HTML page using:
<xsl:value-of select="#[ColumnName]" />
in ItemStyle.xml, I get [url], [document name] in the page. I would like to display this as a URL can anyone help with the XSL?
You could use:
<xsl:value-of select="substring-before(#[ColumnName],',')"/>
or whatever the separator is.
Thanks everyone, in the end I figured out the following based on a post at sguk
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink1"/>
</xsl:call-template>
</xsl:variable>
with the following a tag code:
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')" />
</a>
or for an image:
<xsl:variable name="Image">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#img" />
</xsl:call-template>
</xsl:variable>
with the following img tag:
<img src="{substring-before($Image,',')}" alt="{substring-after($Image,',')}" />
I'm posting the solution back here as this proved ludicrously hard to figure out (probably my fault as I don't really 'get' XSL) but just in case anybody is looking for it, this code outputs images or links from the 'Hyperlink or Picture' column type in Sharepoint.
Another thing you can do is to take a list that shows URLs properly (like a Links list) and use SharePoint Designer to convert it to a DataView WebPart. In there will be the proper XSL for doing the conversion.
The easiest way to do this is with SharePoint designer:
click the field that shows "http://link, description"
a box with an > will appear, click it and you will get a "common xsl:value-of tasks" flyout.
It will have the field name and type, with the type set to "text".
Change the type to "hyperlink" and you will get a box allowing you to format the hyperlink. It will have all the necessary xsl already populated but you can input your own text or remove the link.
This hopefully helps. It shows "Project Site" when the hyperlink is entered and spaces when not.
<!--Project Site--><TD Class="{$IDAAO2UG}">
<xsl:variable name="Field" select="#Project_x0020_Site" />
<xsl:choose>
<xsl:when test="substring-before(#Project_x0020_Site, ', ')=''"><xsl:value-of select="substring-after(#Project_x0020_Site, ', ')" /></xsl:when>
<xsl:otherwise><A HREF="{substring-before(#Project_x0020_Site, ', ')}">
<xsl:choose>
<xsl:when test="substring-after(#Project_x0020_Site, ', ')=''"><xsl:value-of disable-output-escaping="no" select="substring-before(#Project_x0020_Site, ', ')" /></xsl:when>
<xsl:otherwise><xsl:value-of select="substring-after(#Project_x0020_Site, ', ')" /></xsl:otherwise>
</xsl:choose>
</A></xsl:otherwise>
</xsl:choose>
</TD>
In SharePoint 2013 you have to do things a bit differently because the #Url attribute is is no longer delimited with a comma. There is now a .desc sub property of #Url. Below is an example of how this works hopefully this saves someone else some time.
<xsl:template name="dvt_1.rowview">
<xsl:if test="string-length(#URL) > 0">
<div class="link-item item">
<a title="{#Comments}" target="_blank" href="{#URL}">
<xsl:value-of select="#URL.desc" />
</a>
</div>
</xsl:if>
</xsl:template>

Resources