我使用xslt 1.0对xhtml文件进行一些操作 . 但我想从一个相同的副本开始 . 令我惊讶的是 xsl adds attributes that were absent in the original file . 请解释一下这种现象 . 我宁愿避免使它更容易比较源文件和结果文件 .
我尝试了xsltproc和msxsl . 没有不同 . 我将 rowspan
和 colspan
添加到所有 td
元素中 .
输入:
<?xml version="1.0" encoding="windows-1250" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
<title>Anything</title>
</head>
<body>
<table>
<tr><td class="skl" >test</td><td class="kwota" >1 800,00</td></tr>
</table>
</body>
</html>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
<xsl:output method="xml"
omit-xml-declaration="no"
encoding="windows-1250"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates
select="node()|@*|processing-instruction()|comment()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
唯一的区别是这一行:
<tr><td class="skl" rowspan="1" colspan="1">test</td><td class="kwota" rowspan="1" colspan="1">1 800,00</td></tr>
针对dtd验证源文件没有显示错误 . 我可以将这些属性插入到源文件中以解决问题,但我很好奇这个混乱的原因 .
Edit: 我使用原始dtd下载(延迟20秒)
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
<!ATTLIST td
%attrs;
abbr %Text; #IMPLIED
axis CDATA #IMPLIED
headers IDREFS #IMPLIED
scope %Scope; #IMPLIED
rowspan %Number; "1"
colspan %Number; "1"
%cellhalign;
%cellvalign;
>
2 回答
您的XSLT处理器运行正常 . 没有添加新属性 . rowspan属性始终通过DTD引用输入到输入文件中 . 将rowspan的值“1”序列化为显式属性或者doctype声明隐含的值对模型数据没有影响 .
上面的ATTLIST显示rowspan和colspan的默认值为1.没有办法 not 具有这些属性并且仍然符合XHTML 1.1 strict . 注释为#IMPLIED的其他属性表示它们是可选的 .
我希望能够解释它 .
有几种方法可以禁用我能够测试的处理器中的“功能” .
libxml
xsltproc :
--nodtdattr
libxslt / libxml :加载源时不要指定
XML_PARSE_DTDATTR
,例如xmlReadFilemsxml
msxsl :
-xe
- 不解决外部问题Msxml.DomDocument :
doc.resolveExternals = False
和doc.validateOnParse = False
之前load
,也禁用整个dtdresolveExternals:
是的,这是愚蠢的 . 但我只是从MS复制它 . 应该是3.0和4.0真,我猜是6.0 .
6.0 SP1中引入的PopulateElementDefaultValues Property有一个很有吸引力的描述,但它对我的dtds不起作用 .