0

I hope someone can help me with this...

I am using SharePoint 2013 and trying to render a CQWP to show the latest blog posts. The problem I have is that when displaying the 'content' from the post I get '&#160' added and quotes are shown as '&quot'. I have managed to strip the HTML mark up but can't seem to get rid of these.

My code is as follows - any help would be much appreciated, thanks.

Generate Summary and Remove HTML

<!-- Generate Summary -->
    <xsl:template name="GenerateSummary">
    <xsl:param name="Content"/>
    <xsl:param name="Length"/>
    <xsl:param name="Suffix"/>
    <xsl:variable name="cleanContent">
        <xsl:call-template name="RemoveHtml">
        <xsl:with-param name="String" select="$Content"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:call-template name="SubstringBeforeLast">
        <xsl:with-param name="String"
        select="substring($cleanContent, 1, $Length)"/>
        <xsl:with-param name="Char" select="' '"/>
    </xsl:call-template>
    <xsl:if test="string-length($cleanContent) &gt; $Length">
        <xsl:value-of select="$Suffix"
        disable-output-escaping="yes"/>
    </xsl:if>
    </xsl:template>

    <!-- RemoveHTML -->
    <xsl:template name="RemoveHtml">
      <xsl:param name="String"/>
      <xsl:choose>
        <xsl:when test="contains($String, '&lt;')">
          <xsl:value-of select="substring-before($String, '&lt;')"/>
          <xsl:call-template name="RemoveHtml">
            <xsl:with-param name="String"
              select="substring-after($String, '&gt;')"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$String"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
    <xsl:template name="SubstringBeforeLast">
      <xsl:param name="String" />
      <xsl:param name="Char" />
      <xsl:param name="subsequent"/>
      <xsl:choose>
        <xsl:when test="contains($String, $Char)">
          <xsl:if test="$subsequent = 1">
            <xsl:value-of select="$Char"/>
          </xsl:if>
          <xsl:value-of select="substring-before($String, $Char)"/>
          <xsl:call-template name="SubstringBeforeLast">
            <xsl:with-param name="String"
              select="substring-after($String, $Char)" />
            <xsl:with-param name="Char" select="$Char" />
            <xsl:with-param name="subsequent" select="1"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="$subsequent != 1">
            <xsl:value-of select="$String"/>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

Calling it here

<div class="fcItemContent">                 
    <xsl:call-template name="GenerateSummary">
      <xsl:with-param name="Content" select="@content" />
      <xsl:with-param name="Length" select="200" />
      <xsl:with-param name="Suffix" select="'...'"/>
    </xsl:call-template>
</div>
  • Is it possible to show the input XML? In particular, what is the literal value of the `content` attribute you are passing to the `GenerateSummary` template? – Tim C Jan 06 '16 at 13:30
  • Hi, It's passing through the text that is entered into the body field when writing a blog post. But adds HTML formatting - when stored/saved, I am populating the front page with this data then stripping the HTML markup but still getting the mentioned characters. The HTML is pretty basic with divs and p tags – Richard Griffiths Jan 06 '16 at 14:29

1 Answers1

1

Use function of XSLT

normalize-space()

**<xsl:value-of select="normalize-space()"/>**

White space is normalized by stripping leading and trailing white space and replacing sequences of white space characters with a single space. If the argument is omitted, the string-value of the context node is normalized and returned.

referred Link :

Remove Space using XSLT

Dipen Shah
  • 184
  • 9
  • Thank you for your advice but unfortunatley this hasnt worked. I still get the following result in my text being displayed: "Hello World, testing" and quotes appear as &quotCity&quot – Richard Griffiths Jan 06 '16 at 13:04