You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何xsltproc会将带重音的字符转换为十六进制实体?

解决XSLT输出XML时属性值中不必要的十六进制实体问题

解决方案

1. 修改XSL样式表,明确指定输出编码

更新stylesheet.xsl中的<xsl:output>节点,添加encoding="UTF-8"属性:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes" encoding="UTF-8" />

  <xsl:template match="div">
    <tag attribute="{child::text()}"></tag>
  </xsl:template>

</xsl:stylesheet>

2. 执行命令时明确指定输出编码

使用xsltproc的--encoding参数强制输出UTF-8编码:

xsltproc --encoding UTF-8 stylesheet.xsl input.html

原因说明

XML处理器会在输出编码不支持目标字符时,将其转义为实体。xsltproc默认可能未明确设置输出编码,导致它采用仅支持ASCII的编码规则,因此将ó这类非ASCII字符转成了十六进制实体&#xF3;。

通过在XSLT中指定encoding="UTF-8",并在命令行强制输出编码为UTF-8,处理器会直接输出UTF-8字符(UTF-8支持所有Unicode字符),无需转义为实体。

内容的提问来源于stack exchange,提问作者Pierre François

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:57:06