我有一个输出 HTML 的转换。为了避免可能在旧浏览器中中断的自关闭标签(例如<img />
,而不是<img></img>
),输出方法必须是html
. 然后虽然应用了 URL 编码,但它破坏了我的应用程序。参见例如:
输入
<html>
<head>
</head>
<body>
{{example}}
<a href="{{example}}" >abc</a>
<img src="http://placehold.it/20x20"></img>
</body>
</html>
转型
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" /><!-- either -->
<xsl:output method="html" indent="yes" /><!-- or -->
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
</xsl:transform>
在第一种情况下,输出是:
<?xml version="1.0"?>
<html>
<head>
</head>
<body>
{{example}}
<a href="{{example}}">abc</a>
<img src="http://placehold.it/20x20"/>
</body>
</html>
在第二种情况下,输出是:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
{{example}}
<a href="%7B%7Bexample%7D%7D">abc</a>
<img src="http://placehold.it/20x20">
</body>
</html>
第一种情况的好处是该@href
属性不是 URL 编码的。这对我的应用程序来说是必须的。第二种变体虽然不好但更好地实现了,但它<img>
是自动关闭的。这不能用于<img>
标签和其他一些。
有没有办法获得method="html"
没有 URL 编码的好处?如果是,如何?