Compare Author to UserID in SharePoint XSLT - sharepoint

I've got a simple DataFormWebPart where I'm using XSLT to render out the contents of list. I want to compare the #Author field each list item to the current user, however the following won't evaluate to true:
in the header of the XSL:
<xsl:param name="UserID" />
and within the template that evaluates the rows:
<xsl:value-of select="#Author" />
<xsl:if test="#AuthorID = $UserID">(you)</xsl:if>
I have values for both #Author and $UserID:
#Author renders as a hyperlink to their user-profile
$UserID renders as the same text, but without the hyperlink.
What expression can I use to get the non-hyperlink value of the user-profile?

Found a quick win:
<xsl:value-of select="contains(#Author,concat('>',$UserID,'<'))" />

Should refer
https://sharepoint.stackexchange.com/questions/21202/custom-form-does-not-display-created-by-value
<tr>
<td valign="top" class="ms-formlabel"><nobr>Created by</nobr></td>
<td valign="top" class="ms-formbody">
<SharePoint:CreatedModifiedInfo ControlMode="Display" runat="server">
<CustomTemplate>
<SharePoint:FormField FieldName="Author" runat="server" ControlMode="Display" DisableInputFieldLabel="true" /><br/>
<SharePoint:FieldValue FieldName="Modified" runat="server" ControlMode="Display" DisableInputFieldLabel="true"/>
</CustomTemplate>
</SharePoint:CreatedModifiedInfo>
</td>

Related

xpath: How do I extract text within the "strong" tag?

I'm using scrapy and need to extract "Gray / Gray" using xpath selectors.
Here's the html snippet:
<div class="Vehicle-Overview">
<div class="Txt-YMM">
2006 GMC Sierra 1500
</div>
<div class="Txt-Price">
Price : $8,499
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
class="Table-Specs">
<tr>
<td>
<strong>2006 GMC Sierra 1500 Crew Cab 143.5 WB 4WD
SLE</strong>
<strong class="text-right t-none"></strong>
</td>
</tr>
<tr>
<td>
<strong>Gray / Gray</strong><br />
<strong>209,123
Miles
/ VIN: XXXXXXXXXX
</td>
</tr>
</table>
I'm stuck trying to extract "Gray / Gray" within the "strong" tag. Any help is appreciated.
This XPath will work in Scrapy and also in Google/Firefox Developer's Console:
//div[#class='Vehicle-Overview']/table[#class='Table-Specs']//tr[2]/td[1]/strong[1]/text()
You can use this code in your spider:
color = response.xpath("//div[#class='Vehicle-Overview']/table[#class='Table-Specs']//tr[2]/td[1]/strong[1]/text()").extract_first()
You can use this XPath expression with your sample XML/HTML:
//div[#class='Vehicle-Overview']/table[#class='Table-Specs']/tr[2]/td[1]/strong[1]
A full XPath given the full file mentioned below with respect to a namespace "http://www.w3.org/1999/xhtml" can be
/html/body/div/div/div[#class='content-bg']/div/div/div[#class='Vehicle-Overview']/table[#class='Table-Specs']/tr[2]/td[1]/strong[1]

rich faces selectionChangeListener for two different column

I have a richtree like this :
<rich:tree id="positionTree"
value="#{positionAdminBean.positionTree}"
var="pos" switchType="ajax" binding="#positionAdminBean.htmlTree}"
nodeSelectListener="#{positionAdminBean.onCmdSelectPosition}"
ajaxSubmitSelection="true" reRender="positionPanel,mainTabbedPane,selectGroupPanel">
<rich:treeNode id="treeNodeId">
<table width="100%">
<tr>
<td width="50%">
<h:outputText value="#{pos.name}" id="treeposNameId"/>
</td>
<td width="40%">
<h:outputText value="#{pos.humanResourceName}" id="treeposHumanResName"/>
</td>
</tr>
</table>
</rich:treeNode>
</rich:tree>
these codes generate and show a tree of data correctly.
but my problem is that when you click on a row it fires nodeSelectListener="#{positionAdminBean.onCmdSelectPosition}".
as you see my tree has two columns , I need to do something with this code that every columns has its own select listener .
or do something that when user click on each columns it does different works
Well, a nodeSelectListener is fired when a node is selected. You can not assign it to something that is only a part of the node.
You can define an <a4j:jsFunction> and call it when the table cell is clicked.
<a4j:jsFunction name="firstColumnListener" actionListener="#{bean.doSomething}" … >
<a4j:param name="id" assignTo="#{bean.selectedId}" />
</a4j:jsFunction>
<td onclick="firstColumnListener(id)">
…
</td>

expression engine search result related

I want to display up to 200 words of the related results just in the next line to title
But i am not getting the text that {excerpt} should Display
My code is written below
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
<table border="0" cellpadding="6" cellspacing="1" width="100%">
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
<tr class="{switch}">
{if page_meta_title != ""} <td width="30%" valign="top"><b>{title}</b></td>{/if}
</tr>
<tr><td style="color:red!important">{excerpt}</td></tr>
{if count == total_results}
</table>
{/if}
{paginate}
<p>Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}
{/exp:search:search_results}
</table>
Maybe this was just a typo in your question, but it looks like you have the opening search tag listed twice.
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
<table border="0" cellpadding="6" cellspacing="1" width="100%">
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
Also, the excerpt tag by default allows 50 characters. You can also consider the character limiter plugin (http://devot-ee.com/add-ons/character-limiter) which is a free plugin from Ellis Lab. Once you have that setup, you would use it like so....
{exp:char_limit total="200" exact="no"}{your_text_field}{/exp:char_limit}

how to concatenate (part of) variable to String in XSLT

I would like to see the first couple of characters of the variable 'vari' to be concatenated to String abc=' here:
href="{concat('abc=', substring-before('vari', '='))}"
Here is the whole snippet:
<xsl:template match="report:subelement">
<tr>
<td>
<message>
<xsl:variable name="vari" select="."></xsl:variable>
<xsl:copy-of select="." />
</message>
</td>
<td>
<button type="button" onclick="window.location.href=this.getAttribute('href')" href="{concat('abc=', substring-before('vari', '='))}" >Kill thread</button>
</td>
</tr>
</xsl:template>
that is probably a trivial question but I am just learning xslt.
You are quite close, but:
To access the value of a variable you have to use an dollar ($) as prefix. Do not put variable name in apostrophe.
Therefore try:
href="{concat('abc=', substring-before($vari, '='))}
Than this will throw an error because your variable declaration is not in the same context as the usage.
The variable declaration has to be in the same element or in an ancestor. Put the declaration at the top of the subelement template or the in the <tr element.
Updated working template:
<xsl:template match=""report:subelement">
<xsl:variable name="vari" select="."></xsl:variable>
<tr>
<td>
<message>
<xsl:copy-of select="." />
</message>
</td>
<td>
<button type="button" onclick="window.location.href=this.getAttribute('href')"
href="{concat('abc=', substring-before($vari, '='))}" >Kill thread</button>
</td>
</tr>
</xsl:template>

DataView WebPart in sharepoint designer

I would like to display the list items using DataView WebPart and I am successful so far. But I would like to show the items in two columns for each row, instead of one columns per one row. How can i achieve this.
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">ms-alternating</xsl:attribute>
</xsl:if>
<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
<td class="ms-vb" width="1%" nowrap="nowrap">
<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(#ID))" ddwrt:ammode="view"></span>
</td>
</xsl:if>
<xsl:variable name="ImageURL">
<xsl:value-of select="#ImageURL" />
</xsl:variable>
<td class="ms-vb">
<img alt="" src="{$ImageURL}" />
</td>
</tr>
I would like to show the items from a list in two columns and the table should be increased dynamically based on the number of items. Can someone guide me on how to achieve this.
Actually you can achieve this more easily with Item Lister Web Part. Try to check that out.

Resources