如何使用Diazo保留HTML实体

如何使用Diazo保留HTML实体

本文介绍了如何使用Diazo保留HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的Diazo规则文件:

I have the following simple Diazo rules file:

<rules
  xmlns="http://namespaces.plone.org/diazo"
  xmlns:css="http://namespaces.plone.org/diazo/css"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <theme href="theme/theme.html" />

  <replace css:theme-children="#content" css:content-children=".content" />

</rules>

和主题:

<html>
  <body>
    <div id="content">
        Lorem ipsum ...
    </div>
  </body>
</html>

我要转换的源是:

<html>
  <body>
    <div class="content">
        <a href="&#0109;&#0097;&#0105;lt&#0111;&#0058;info&#0064;example&#46;org">info</a>
    </div>
  </body>
</html>

我得到的是

... <a href="mailto:[email protected]">info</a> ...

但是我想保持href属性的HTML实体完整.我如何用重氮做到这一点?

but I want to keep the HTML entities of the href attribute intact. How can I do this with Diazo?

推荐答案

请注意,数字字符引用不是实体引用,因此您的标题有点误导(保留或不包含诸如&& nbsp;之类的实体引用的答案是完全不同)

Note numeric character references are not entity references so your title is a bit misleading (the answer for preserving or not entity references such as "& n b s p ; " is very different)

我不知道Diazo,但是如果您添加XSLT,

I don't know Diazo but in XSLT if you add

 <xsl:output encoding="US-ASCII"/>

对于您的文档,则所有非ASCII字符都将使用数字引用输出.

to your document then any non ascii characters will be output using numeric references.

但是,在您的示例中,它们实际上是被引用的ascii字符,例如.".作为 "." xslt 1中没有任何标准方法可以做到这一点(并且如果文档将由兼容的html或xml系统处理,则绝对没有任何理由这样做).任何此类系统都将在处理开始之前将这些引用扩展为其字符. (这就是XSLT无法保留它们的原因:在XSLT看到输入数据之前,它们已被xml解析器删除.)

However in your example they are in fact ascii characters that are quoted such as "." as "." There isn't any standard way in xslt 1 to do that (and there should never be any reason to do that if the document is going to be processed by a conforming html or xml system). Any such system will expand those references to their characters before processing starts. (Which is why XSLT can not preserve them: they have been removed by the xml parser before XSLT sees the input data.)

这篇关于如何使用Diazo保留HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 07:30