如果有德语字符,则XSLT无法转换
我正在使用1.0 XSLT版本,但是德语字符有问题。如果输入的XML元素数据中有任何德语字符,则XSLT无法转换任何内容,并且输出完全为空。
一个简单的例子:
<root>
<table name=\"users\">
<row>
<field attr1=\"name\">GÜNTER</field>
</row>
</table>
</root>
输出应为:
<users>
<name>GUENTER</name>
</users>
我在XSL中使用utf-8编码,并且在使用Eclipse时可以对其进行转换。在我的应用程序中,这些XSL文件存储在Oracle数据库中,并在应用程序启动时进行缓存。但是我的Java应用程序无法对此进行转换,并引发以下错误:
2字节UTF-8序列的无效字节2
这是主要的XSL:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:include href=\"functions.xsl\" />
<xsl:output encoding=\"utf-8\" method=\"xml\" indent=\"yes\" />
<xsl:template match=\"/\">
<users>
<name>
<xsl:call-template name=\"replaceCH\">
<xsl:with-param name=\"value\" select=\"//root/table[@name=\'users\']/row/field[@attr1=\'name\']\"/>
</xsl:call-template>
</name>
</users>
</xsl:template>
</xsl:stylesheet>
这是functions.xsl:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<xsl:stylesheet version=\"1.0\"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:template name=\"replace\">
<xsl:param name=\"text\"/>
<xsl:param name=\"search\"/>
<xsl:param name=\"replace\"/>
<xsl:choose>
<xsl:when test=\"contains($text, $search)\">
<xsl:variable name=\"replace-next\">
<xsl:call-template name=\"replace\">
<xsl:with-param name=\"text\" select=\"substring-after($text, $search)\"/>
<xsl:with-param name=\"search\" select=\"$search\"/>
<xsl:with-param name=\"replace\" select=\"$replace\"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select=\"concat(substring-before($text, $search),$replace,$replace-next)\"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select=\"$text\"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name=\"replaceCH\">
<xsl:param name=\"value\"/>
<xsl:variable name=\"temp\">
<xsl:call-template name=\"replace\">
<xsl:with-param name=\"text\" select=\"$value\"/>
<xsl:with-param name=\"search\" select=\"\'_\'\"/>
<xsl:with-param name=\"replace\" select=\"\'\'\"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=\"temp1\">
<xsl:call-template name=\"replace\">
<xsl:with-param name=\"text\" select=\"$temp\"/>
<xsl:with-param name=\"search\" select=\"\'Ö\'\"/>
<xsl:with-param name=\"replace\" select=\"\'OE\'\"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=\"temp2\">
<xsl:call-template name=\"replace\">
<xsl:with-param name=\"text\" select=\"$temp1\"/>
<xsl:with-param name=\"search\" select=\"\'Ü\'\"/>
<xsl:with-param name=\"replace\" select=\"\'UE\'\"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select=\"$temp2\"/>
</xsl:template>
</xsl:stylesheet>
当我将XSL存储到数据库时,Ö和Ü看起来像Ã?
:
<xsl:with-param name=\"search\" select=\"\'Ã?\'\"/>
我使用Hibernate并按如下方式配置编码:
hibernate.connection.characterEncoding = utf-8
我怎么解决这个问题?
没有找到相关结果
已邀请:
2 个回复
窃誓额
藐刚