【发布时间】:2020-12-03 05:05:00
【问题描述】:
我正在努力将 XML 转换为 HTML。因为 Meta 元素不会在 Html 的输出中关闭。
XML 输入:
<topic>
<title>Sample</title>
</topic>
我正在使用的 XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="no"/>
<xsl:template match="topic" mode="chapterHead">
<head>
<xsl:call-template name="generateCharset"/>
</head>
</xsl:template>
<xsl:template name="generateCharset">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</xsl:template>
</xsl:stylesheet>
我得到的 HTML 输出:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
需要关闭或自行关闭 Meta 元素。
【问题讨论】:
-
我得到的输出是文本
"Sample"。那是因为你的模板有一个模式。如果我删除它,我会得到一个封闭的meta元素 - 那是因为你的输出方法是xml: xsltfiddle.liberty-development.net/6pS2B6R