0

我希望有人可以帮助我解决这个问题...

我正在使用 SharePoint 2013 并尝试呈现 CQWP 以显示最新的博客文章。我遇到的问题是,当显示帖子中的“内容”时,我添加了“   ”,引号显示为“ " ”。我设法剥离了 HTML 标记,但似乎无法摆脱这些标记。

我的代码如下 - 任何帮助将不胜感激,谢谢。

生成摘要并删除 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>

在这里调用

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

1 回答 1

1

XSLT的使用功能

规范化空间()

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

通过去除前导和尾随空格并用单个空格替换空格字符序列来规范化空格。如果省略参数,则将上下文节点的字符串值标准化并返回。

参考链接:

使用 XSLT 删除空间

于 2016-01-06T12:17:48.600 回答