Rup*_*ari 5 java xslt xslt-1.0
我的输入具有类似Í,Â,ÇÁ的重音字符,使用xslt版本1.0我需要渲染这些字符而不做任何更改.
例如:
input Í ÇÂME HOME
output Í ÇÂME HOME
我不想编码/更改那些重音字符,但我得到的输出就像 Ã? ÇÂME HOME
我观察到的是:
Í is converting to Ã?
Ç to Ç
 to Â
如果您观察到所有这些字符都转换为大写字母a,则使用其他字符(, ? ‡ )
任何人都可以帮助我我的样式表看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:element name="root">
<xsl:value-of select="/../inputpath/msg"/>
<\xsl:element>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
用于转换xml的代码
public static String transformByXslt(final String input, final String styleSheet,
final Map<String, String> parameterMap, final ProductMetadata productMetadata,
final ProductInstance productInstance, final Map<String, Object> daoMap) throws TransformerException,
UnsupportedEncodingException, ValidationException, NoNeedToRenderException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final TransformerFactory factory = TransformerFactory.newInstance();
InputStream inputStream = null;
inputStream = new ByteArrayInputStream(input.getBytes("UTF-8"));
Transformer transformer = factory.newTransformer(new StreamSource(new ByteArrayInputStream(styleSheet
.getBytes())));
setParamsForXslt(transformer, parameterMap, productMetadata, productInstance, daoMap);
transformer.setErrorListener(new PbErrorListener());
try {
transformer.transform(new StreamSource(inputStream), new StreamResult(out));
} catch (TransformerException e) {
if (ExceptionUtils.getRootCause(e) != null
&& ExceptionUtils.getRootCause(e).getClass().equals(ValidationException.class)) {
throw new ValidationException(e);
} else if (ExceptionUtils.getRootCause(e) != null
&& ExceptionUtils.getRootCause(e).getClass().equals(NoNeedToRenderException.class)) {
throw new NoNeedToRenderException(e);
} else if (ExceptionUtils.getRootCause(e) != null
&& ExceptionUtils.getRootCause(e).getClass().equals(BlankRenditionException.class)) {
return "";
} else {
throw e;
}
}
return out.toString("UTF-8");
}
Run Code Online (Sandbox Code Playgroud)
Rupesh,您将 UTF-8 编码数据视为单字节编码数据或对 UTF-8 进行两次编码。(这
out.toString("UTF-8")
Run Code Online (Sandbox Code Playgroud)
???)
第一步是弄清楚您的数据采用什么编码以及您应该生成什么编码。例如,如果您使用Notepad++,它有一个“编码”菜单,其中显示文件的当前编码并允许您更改它,查看效果。告诉我们这是什么故事。
您可能需要西欧 Windows 编码:windows-1252
还要检查这一点:XSL 输出元素的编码属性
如果您愿意的话,我可以给您一些 C# 示例,但是您运行 Java...
| 归档时间: |
|
| 查看次数: |
1240 次 |
| 最近记录: |