Situation:

After I migrated our public website from SharePoint 2010 to SharePoint 2013, I was running into a situation. Basically, when user create a new page and add image caption(Which will be queried and showed on Content Query Web Part), it automatically fill in <P> element into it.  And this <P> will be showed up on front page.

 

Task:

Yes user can go to source and delete <P> manually, which is not smart enough.

 

Action:

 

Using SharePoint Designer 2013, connect to site, go the the ItemStyle.xsl under Home>Style Library>XSL Style Sheet>

Find the template you are using by its name. I.E.

<xsl:template name="Default" match="*" mode="itemstyle">

 

Now go to the description part, i.e. :

 <div class="description" style="padding-left: 5px;  font-family:cambria;font-size : 14px; text-decoration: none;">
<xsl:value-of select="@Description" />
</div>

 

Simple change

<xsl:value-of select="@Description" />

into

<xsl:if test="not(starts-with(@Description, '&#x3c;'))">
    <xsl:value-of select="@Description"  />
</xsl:if>
<xsl:if test="starts-with(@Description, '&#x3c;')">
   <xsl:value-of select="substring(@Description,4,string-length(@Description)-7)"  />
</xsl:if>

 

Explaination: 

'&#x3c;' is the Hex code for html sign '<', and the first if simply check if the text is not start with '<', output as what it is. The second if check if the text start with'<", then chop the <p> and </p> off. then output the processed text.

Hopefully this can help.


Reference:

http://p2p.wrox.com/xslt/62235-stripping-last-x-characters.html

http://do.remifa.so/archives/unicode/latin1.html

http://www.dpawson.co.uk/xsl/sect2/replace.html

http://www.keller.com/xslt/9/

http://stackoverflow.com/questions/12508566/xsl-if-test-starts-with

 

 

About Lei

I am an IT specialist with over 10 year experience - years on Automation, on-Premise or Azure.

I am happy to develop however never want be a full time developer. Only do what I have to do. If it has to be PowerShell,HTML, PHP, CSS, C#, VBS or JS, front end or backend, so be it, doesn't matter!

Spent years with Windows, SCCM, SharePoint, SQL and Exchange servers. For last several years, I have been actively working under On Premise > Azure environment.

THERE IS NO WAY BACK!!!

Current Certificates:
    Microsoft® Certified-
  • -Enterprise Administrator
  • -Database Administrator
  • -SharePoint Administrator
  • -Administering and Deploying SCCM 2012
Red Hat Certified Technician
ITIL V3 Foundation - Practitioner

Working on Azure Certificates now and hopefully they can stop upgrading their questions one day! GIVE ME A BREAK!

Contact Lei

Name *
Email *
Comments *

Traffic since 10/08/2016

Today13
Yesterday83
This week637
This month1933
Total416293

Visitor Info

  • IP: 54.221.73.186
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online

1
Online

2017-12-17

Login