简体   繁体   English

如何使用Diazo保存HTML实体?

[英]How can I preserve HTML entities with Diazo?

I have the following simple Diazo rules file: 我有以下简单的Diazo规则文件:

<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>

and theme: 和主题:

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

The source I want to transform is: 我要转换的源是:

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

What I get is 我得到的是

... <a href="mailto:info@example.org">info</a> ...

but I want to keep the HTML entities of the href attribute intact. 但我想保持href属性的HTML实体不变。 How can I do this with Diazo? 我如何用重氮做到这一点?

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 "& nbsp ; " is very different) 请注意,数字字符引用不是实体引用,因此您的标题有点误导(保存或不包含实体引用(例如“&nbsp;”的答案非常不同))

I don't know Diazo but in XSLT if you add 我不知道Diazo,但是如果您添加XSLT

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

to your document then any non ascii characters will be output using numeric references. 到您的文档,则任何非ascii字符都将使用数字引用输出。

However in your example they are in fact ascii characters that are quoted such as "." 但是,在您的示例中,它们实际上是被引用的ascii字符,例如“。”。 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). xslt 1中没有任何标准方法可以做到这一点(并且如果文档将由兼容的html或xml系统处理,则绝对没有理由这样做)。 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.) (这就是XSLT无法保留它们的原因:在XSLT看到输入数据之前,它们已被xml解析器删除。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM