我正在尝试清理一些 html。我已经用 tidy 将它们转换为 xhtml
$ tidy -asxml -i -w 150 -o o.xml index.html
生成的 xhtml 最终具有命名实体。 在这些 xhtml 上尝试 xsltproc 时,我不断收到错误。
$ xsltproc --novalid -o out.htm t.xsl o.xml
o.xml:873: parser error : Entity 'mdash' not defined
resources to storing data and using permissions — as needed.</
^
o.xml:914: parser error : Entity 'uarr' not defined
</div><a href="index.html#top" style="float:right">↑ Go to top</a>
^
o.xml:924: parser error : Entity 'nbsp' not defined
Android 3.2 r1 - 27 Jul 2011 12:18
如果我将 --html 添加到 xsltproc,它会提示具有相同名称(有效)的 name 和 id 属性的标签
$ xsltproc --novalid --html -o out.htm t.xsl o.xml o.xml:845: element a: validity error : ID top already defined
<a name="top" id="top"></a>
^
xslt 很简单:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[@id=side-nav]"/>
</xsl:stylesheet>
为什么 --html 不起作用?它为什么提示?还是我应该忘记它并修复实体?
最佳答案
我采用了另一种方式 - 让 tidy 生成数字实体而不是使用 -n 选项命名。
$ tidy -asxml -i -n -w 150 -o o.xml index.xml
现在我可以删除 --html 选项并且它起作用了。 虽然我可以删除那个名称属性,但仍然想知道为什么它会报错,虽然它是valid
关于html - xsltproc html 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6887796/