【问题标题】:Removing &#160 with XSLT使用 XSLT 删除 &#160
【发布时间】:2016-04-10 10:49:24
【问题描述】:

我希望有人能帮我解决这个问题...

我正在使用 SharePoint 2013 并尝试呈现 CQWP 以显示最新的博客文章。我遇到的问题是,当显示帖子中的“内容”时,我添加了“ ”,并且引号显示为“&quot”。我设法去掉了 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>

【问题讨论】:

  • 是否可以显示输入的 XML?特别是,您传递给GenerateSummary 模板的content 属性的字面值是多少?
  • 您好,这是通过在写博客文章时输入到正文字段中的文本。但是添加了 HTML 格式 - 存储/保存时,我用这些数据填充首页,然后剥离 HTML 标记,但仍然得到提到的字符。 HTML 非常基础,带有 div 和 p 标签

标签: xslt sharepoint-2013 cqwp


【解决方案1】:

使用XSLT的功能

标准化空间()

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

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

参考链接:

Remove Space using XSLT

【讨论】:

  • 感谢您的建议,但不幸的是,这没有奏效。在显示我的文本时,我仍然得到以下结果:“Hello World, testing”并且引号显示为“City”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多