防止<cite>标记出现在RSS Feed中

mag*_*000 2 xslt rss coldfusion

我使用doctype:XHTML Mobile Profile 1.2,XML version ="1.0 and Content-Type"application/xhtml + xml"

是否可以禁用或阻止<cite>标记出现在RSS提要中,因为我不断在页面本身上收到此错误.

error on line 24 at column 70: expected '>'
Below is a rendering of the page up to the first error.
Run Code Online (Sandbox Code Playgroud)

我正在使用来自其他网站的外部供稿,这不是我的控制或编辑.

我正在使用XSLT和ColdFusion文件来读取外部RSS文件,并在我的XSLT中以我想要的方式显示它,我已经到位disable-output-escaping="yes"以防止丢失代码显示在feed中.当这个标签不存在时,我的XSLT工作

我试图绕过它,但没有运气.实际上可以这样做吗?

CFM

<cfcontent type="application/xhtml+xml" reset="yes">
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">

<cfhttp method="Get" url="http://www.animenewsnetwork.com/news/rss.xml">
<cfset xmlInput = CFHTTP.FileContent>
<cfset MyXslFile = Expandpath("animenewsrss.xsl")>
<cffile action="READ" variable="xslInput" file="#MyXslFile#">
<cfset xmlOutput = XMLTransform(xmlInput, xslInput)>
<cfoutput>#xmloutput#</cfoutput>
Run Code Online (Sandbox Code Playgroud)

XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" omit-xml-declaration="yes" />

<xsl:template match="rss/channel">
    <xsl:element name="html">
      <xsl:element name="head">
     <xsl:element name="title">Anime News</xsl:element>
      </xsl:element>
      <xsl:element name="body">
      <xsl:element name="div"><xsl:attribute name="id"><xsl:value-of select="'hstyle'"/></xsl:attribute>Media Events UK - Anime News</xsl:element>
      <xsl:element name="div"><xsl:attribute name="id"><xsl:value-of select="'nstyle'"/>
        </xsl:attribute><xsl:element name="a"><xsl:attribute name="href">index.cfm</xsl:attribute>Home</xsl:element> - 
        <xsl:element name="a"><xsl:attribute name="href">listings.cfm</xsl:attribute>Listings</xsl:element> - 
        <xsl:element name="a"><xsl:attribute name="href">venue.cfm</xsl:attribute>Venues</xsl:element>
        </xsl:element>
        <xsl:apply-templates select="item[position() &lt; 6]" />
      </xsl:element>
    </xsl:element>
</xsl:template>

<xsl:template match="item[position() &lt; 6]">
  <div class="rsstyle">
        <xsl:element name="a">
            <xsl:attribute name="href">
            <xsl:value-of select="link"/>
            </xsl:attribute>
            <xsl:value-of select="title" />
        </xsl:element>
        <xsl:element name="div">
        <xsl:value-of select="pubDate" />
        </xsl:element>
        <xsl:element name="div">
        <xsl:value-of select="concat(substring(description, 1, 50), '...')" disable-output-escaping="yes"/>
        </xsl:element>
</div>
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

Mat*_*ler 5

有了这条线

<xsl:value-of select="concat(substring(description, 1, 50), '...')" disable-output-escaping="yes"/>
Run Code Online (Sandbox Code Playgroud)

你切割的内容<description>,cite在某些情况下包含元素.这导致您的结果中的行如下HTML:

<div><cite>Ni No Kuni</cite>, <cite>Tales of Xillia</ci...</div>
Run Code Online (Sandbox Code Playgroud)

如您所见,cite元素不再正确关闭,因为您将description元素的内容剪切为50个字符.如果您对字符进行了计数,则会注意到description停止的内容为50,然后插入"...".

如果您描述了将子串应用于decription元素背后的意图,那么SO可以帮助您找到一个很好的替代方案.

我的猜测是你需要考虑description不仅包含文本,还包含元素(如cite)的可能性.然后,仅在描述的文本内容上使用子字符串是有意义的,如下所示:

concat(substring(description/text(),1,50),'...')
Run Code Online (Sandbox Code Playgroud)

然后继续捕获子元素description,例如在单独的模板中:

<xsl:template match="cite[parent::description]">
  <!--Deal with cite elements-->
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

编辑:我调整了你的样式表来处理cite作为孩子的元素description.有2个额外的模板可以处理文本节点和cite节点,它们都是子节点description.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />

<xsl:template match="rss/channel">
  <!--I left this template unchanged!-->
</xsl:template>

<xsl:template match="item[position() &lt; 6]">
  <div class="rsstyle">
    <xsl:element name="a">
        <xsl:attribute name="href">
        <xsl:value-of select="link"/>
        </xsl:attribute>
        <xsl:value-of select="title" />
    </xsl:element>
    <xsl:element name="div">
    <xsl:value-of select="pubDate" />
    </xsl:element>
    <xsl:element name="div">
    <xsl:apply-templates select="description"/>
    </xsl:element>
  </div>
</xsl:template>

<xsl:template match="description">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()[parent::description]">
  <xsl:copy/>
</xsl:template>

<xsl:template match="cite[parent::description]">
  <xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)