Removing &#160 with XSLT

835 Views Asked by At

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>
1

There are 1 best solutions below

1
Dipen Shah On

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