How can I preserve HTML entities with Diazo?

人走茶凉 提交于 2020-01-06 06:49:07

问题


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>

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. How can I do this with Diazo?


回答1:


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)

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

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

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

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



来源:https://stackoverflow.com/questions/13006514/how-can-i-preserve-html-entities-with-diazo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!