从XSL中的CDATA标记内渲染HTML标记 [英] Rendering HTML Tags from within CDATA tag in XSL

查看:86
本文介绍了从XSL中的CDATA标记内渲染HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的XML代码中有一个CDATA标记,其中包含一些超链接。

 < smartText><![CDATA [
在单个股票中,S股涨幅最大。 & P。 500是
< a href =’http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=LNC’&Lincoln National Corp< / a>和
< a href ='http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=PLD'>ProLogis</a>]]]> ;
< / smartText>

我正尝试将其转换为HTML页面,如下所示...

 < p class = smartText> 
< xsl:copy-of select = marketSummaryModuleData / smartText />
< / p>

不幸的是,页面上的输出显示为纯文本,而不是html。

$在个别股票中,标普500指数成份股中涨幅最大的股票是标准普尔指数。 500是< a href =’http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric = PLD’> ProLogis< / a>和< a href =’http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric = LNC’&Lincoln National Corp< / a>。

CDATA部分是从经典ASP页面创建的,因此实际的XML输出不包含CDATA部分。这可能是问题的一部分吗?我似乎无法获取要在页面上呈现的信息。我尝试了Google搜索提供的多种解决方案,例如disable-escape-tags,xsl:copy-of,xsl:value-of等。



谢谢

解决方案

您必须更正XML,以便所需的HTML(并且它必须是格式正确的XML)



任何CDATA部分都只是text()节点的一部分,XSLT处理器将其视为此类。

p>

在CDATA中添加标记是公认的不良做法,并且所报告的问题是一种典型的结果。



DOE(禁用-output-escaping)是XSLT中的一项可选功能,并不能保证在不同的XSLT处理器上实现并产生相同的预期结果。



引用 W3C XSLT规范 。:

b
$ b

不需要XSLT处理器支持端口禁用输出转义。如果xsl:value-of或xsl:text指定应禁用输出转义,并且XSLT处理器不支持此功能,则XSLT处理器可能会发出错误信号;否则,将显示错误消息。如果它不表示错误,则必须通过不禁用输出转义来恢复。



和:



由于禁用输出转义可能不适用于所有XSLT处理器,并且可能导致XML格式不正确,因此仅在没有其他选择时才应使用它。


I have a CDATA tag within my XML code which contains some hyperlinks.

<smartText><![CDATA[
Among individual stocks, the top percentage gainers in the S.&P. 500 are
<a href ='http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=LNC'>Lincoln National Corp</a> and 
<a href ='http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=PLD'>ProLogis</a>.]]>
</smartText>

I am trying to transform it into an HTML page as follows...

<p class="smartText">
    <xsl:copy-of select="marketSummaryModuleData/smartText"/>                                    
</p>    

Unfortunately the output onto the page shows up in pure text, not as html.

Among individual stocks, the top percentage gainers in the S.&P. 500 are <a href ='http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric=PLD'>ProLogis</a> and <a href ='http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric=LNC'>Lincoln National Corp</a>.

The CDATA section is being created from a classic ASP page, so the actual XML output does not contain the CDATA section. Could that be part of the problem? I cannot seem to get the information to render on the page. I have tried multiple solutions offered up by Google searches, such as disable-escape-tags, xsl:copy-of, xsl:value-of and more.

Thank you

解决方案

You have to correct the XML so that the desired HTML (and it needs to be well-formed XML) is not contained within a CDATA section.

Any CDATA section is just part of a text() node and the XSLT processor treats it as such.

Putting markup within CDATA is universally acknowledged as bad practice and the reported issue is one typical result.

DOE (disable-output-escaping) is an optional feature in XSLT and is not guaranteed to be implemented and producing the same expected results on different XSLT processors.

To quote the W3C XSLT Spec.:

"An XSLT processor is not required to support disabling output escaping. If an xsl:value-of or xsl:text specifies that output escaping should be disabled and the XSLT processor does not support this, the XSLT processor may signal an error; if it does not signal an error, it must recover by not disabling output escaping. "

and:

"Since disabling output escaping may not work with all XSLT processors and can result in XML that is not well-formed, it should be used only when there is no alternative."

这篇关于从XSL中的CDATA标记内渲染HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆