【问题标题】:XSL Substring-before with HTML charactersXSL Substring-before 与 HTML 字符
【发布时间】:2017-04-27 12:06:40
【问题描述】:

我正在提取一个 rss 提要,其中包含一个笑话,然后是一些链接,用于在不同的服务上分享这个笑话。如下图:

值得注意的是,当我尝试从该输出中复制和粘贴文本时,链接并没有复制到记事本中,而是作为图片粘贴到 MS Word 中。

在我的 XSL 中,我使用 substring-before 试图从我的输出中排除这些链接,但我能想到的唯一一致的字符是超链接中的 <a href,它总是在最后。这可能吗?我第一次通过失败,是否应该包含一个转义字符?

也许我会尝试排除最后一个 X 字符以删除链接

很遗憾,我也找不到提要的 XML 版本,我的来源在这里:http://feeds.feedburner.com/DailyJokes-ACleanJokeEveryday?format=xml

这是我正在使用的 XSL,它目前被硬编码以在最近的笑话结束时中断(我的下一个障碍是遍历这个列表)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
  <xsl:template match="/">
    <xsl:apply-templates select="//item[position() &lt; 2]"/>
  </xsl:template>

  <xsl:template match="item">
    <content-item>
      <h1><xsl:value-of select="title"/></h1>     
          <p><xsl:value-of select="substring-before(description, 'mower')" disable-output-escaping="yes"/></p>
      <br/><br/>
      <p>"The following is here for testing purposes and will be removed"<br/><br/><xsl:value-of select="substring-after(description, 'lawn')" disable-output-escaping="yes"/></p>
      <br/><br/>
    </content-item>
  </xsl:template>
</xsl:stylesheet>

我正在通过 SharePoint 2013 RSS 源 Web 部件呈现我的输出

【问题讨论】:

    标签: xslt rss substring sharepoint-2013 html-escape-characters


    【解决方案1】:

    在尝试查看正确的 XML 时,我发现了解决方案。我查看了源 URL 的页面源,其中我看到最终字符显示如下:

        <title>Hunting with a wife #Joke #Humor</title><description>A hunter visited another hunter and was given a tour of his home. In the den was a stuffed lion.&lt;br /&gt;&lt;br /&gt;The visiting hunter asked, "when did you bag him?"&lt;br /&gt;&lt;br /&gt;The host said, "that was three years ago, when I went hunting with my wife."&lt;br /&gt;&lt;br /&gt;"What's he stuffed with," asked the visiting hunter. "My wife."&lt;div class="feedflare"&gt;
    &lt;a href="http://feeds.feedburner.com/~ff/DailyJokes-ACleanJokeEveryday?a=RT1LsKVBV3Y:0LcrJjJq2X4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DailyJokes-ACleanJokeEveryday?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href....
    

    重点是,a href 没有 &amp;lt; 它使用 HTML 标记 &amp;lt;

    substring-before(description, '&amp;lt;a href') 有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 2014-04-08
      相关资源
      最近更新 更多