问题
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="mailto:info@example.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