【发布时间】:2020-12-06 12:24:45
【问题描述】:
我一直致力于将 HTML 更改为 XML,我在 HTML 输入中有未关闭的 Meta 元素。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
</head>
</html>
未关闭的元元素在输入中未显示任何验证错误,但在进行转换时出现以下错误:
The element type "meta" must be terminated by the matching end-tag "</meta>"
XSL 我试过了:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
xmlns:saxon="http://saxon.sf.net/"
version="2.0">
<xsl:template match="html">
<document>
<xsl:apply-templates/>
</document>
</xsl:template>
<xsl:template match="head">
<head>
<xsl:apply-templates/>
</head>
</xsl:template>
<xsl:template match="title">
<title>
<xsl:apply-templates/>
</title>
</xsl:template>
<xsl:param name="unparse" select="'file:///C:test.htm'"/>
<xsl:template match="saxon:meta">
<xsl:value-of select="saxon:parse-html($unparse)"/>
</xsl:template>
</xsl:stylesheet>
我已经在 XSLT 中尝试了saxon:parse-html,但我无法转换。所以我需要使用 XSLT 删除未关闭的 Meta 元素。我正在使用 saxon-PE 9.9.1.5。
【问题讨论】:
-
不确定您希望与
match="saxon:meta"匹配的元素。我认为它不匹配任何东西,因此永远不会调用 parse-html()。