gpt4 book ai didi

xslt - 防止 标 checkout 现在 RSS Feed 中

转载 作者:行者123 更新时间:2023-12-02 21:41:15 24 4
gpt4 key购买 nike

我使用文档类型:XHTML Mobile Profile 1.2、XML version="1.0 和 Content-Type "application/xhtml+xml"

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

error on line 24 at column 70: expected '>'
Below is a rendering of the page up to the first error.

我正在使用来自另一个网站的外部提要,该网站无法由我控制或编辑。

我正在使用 XSLT 和 ColdFusion 文件来读取外部 RSS 文件,并在 XSLT 中按照我想要的方式显示它,我已经准备好了 disable-output-escaping="yes"以防止在提要中出现丢失代码。当此标记不存在时,我的 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>

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>

最佳答案

用这一行

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

您剪切了<description>的内容,其中包含 cite某些情况下的元素。这会导致结果中出现类似以下的行 HTML :

<div><cite>Ni No Kuni</cite>, <cite>Tales of Xillia</ci...</div>

如您所见,cite元素不再正确关闭,因为您剪切了 description 的内容元素长度为 50 个字符。如果你计算一下字符数,你会发现 description 的内容停在 50,然后插入“...”。

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

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

concat(substring(description/text(),1,50),'...')

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

<xsl:template match="cite[parent::description]">
<!--Deal with cite elements-->
</xsl:template>

编辑:我调整了您的样式表以处理 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>

关于xslt - 防止 <cite> 标 checkout 现在 RSS Feed 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20404615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com