我有一个XML文件和相应的XSLT。我想获得一个可以在带有python的浏览器中运行的HTML文件。
这是我的python代码:
from lxml import etree
dom = etree.parse(path_xml)
xslt =etree.parse(path_xslt)
transform = etree.XSLT(xslt)
newdom = transform(dom)
print(etree.tostring(newdom, pretty_print=True))
问题是我得到的回报是无
因为我是一个初学者,所以我减轻了文件的负担,因为我认为这是问题的原因,但事实证明问题仍然存在:
XML档案:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet "comparexsl.xsl"?>
<!DOCTYPE verification SYSTEM "verif.dtd">
<verification statut=false>
<nberror>2537</nberror>
<f_ref type="t1" value="val"/>
<f_tst type="t2" value=val2"/>
<f_ref type="x" value="20"/>
<f_tst type="x" value="201"/>
<cnxn log="l" mdp="mdp1" />
<option name="MAJ" title="" result="False">
<time time1="116" time2="-31.25" time3="11">
<time_a time1="0" time2=""/>
<time_o time1="15" time2="-40"/></time>
</option>
</verification>
这是我的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" doctype-system="about:legacy-compat" encoding="UTF-8"
indent="yes" />
<xsl:template match="verfication">
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<p><img src="image.jpg" alt="Binevenue"/></p>
<h1 align="center" > Comparaison Status= FALSE </h1>
<p>Nombre d'erreurs = <xsl:value-of select="verification/nberror"/></p>
<p><a href="">See more Details ...</a></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
您的代码中有多种错误来源。您需要同时修改XML文件和XSLT样式表。
在您的XML文件中,
statut
属性值verification
不包含在单引号或双引号中value
属性值,f_tst
没有开头的引号在您的XSLT样式表中,
<xsl:value-of select="verification/nberror"/>
应该<xsl:value-of select="nberror"/>
根据上下文进行阅读(模板与匹配verification
)此外,您的XSLT处理器或浏览器可能无法使用名为“ verif.dtd”的DTD。
输入(已修改)
<?xml version="1.0" encoding="UTF-8" ?>
<verification statut="false">
<nberror>2537</nberror>
<f_ref type="t1" value="val"/>
<f_tst type="t2" value="val2"/>
<f_ref type="x" value="20"/>
<f_tst type="x" value="201"/>
<cnxn log="l" mdp="mdp1" />
<option name="MAJ" title="" result="False">
<time time1="116" time2="-31.25" time3="11">
<time_a time1="0" time2=""/>
<time_o time1="15" time2="-40"/></time>
</option>
</verification>
样式表
<?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" doctype-system="about:legacy-compat" encoding="UTF-8"
indent="yes" />
<xsl:template match="verification">
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<p><img src="image.jpg" alt="Binevenue"/></p>
<h1 align="center" > Comparaison Status= FALSE </h1>
<p>Nombre d'erreurs = <xsl:value-of select="nberror"/>
</p>
<p><a href="">See more Details ...</a></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
细细品味,但alt="Binevenue"
实际上应该是alt="Bienvenue"
法语。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句