Java XSL:为什么我总是在HTML中获得不可读的西班牙语字符
我计划得到一个由XSL和XML文件生成的XHTML页面,现在有一个专注于英语的XSL文件,现在我正在尝试创建一个新的XSL文件来获得西班牙语HTML,但是我得到的HTML无法正确显示西班牙语字符 CDA_es.xsl:(西班牙语单词-Empleado guía telefónica在生成的HTML中始终显示为Empleado guÃ-a telefónica) 在前端:Java XSL:为什么我总是在HTML中获得不可读的西班牙语字符,java,xml,rest,xslt,xhtml,Java,Xml,Rest,Xslt,Xhtml,我计划得到一个由XSL和XML文件生成的XHTML页面,现在有一个专注于英语的XSL文件,现在我正在尝试创建一个新的XSL文件来获得西班牙语HTML,但是我得到的HTML无法正确显示西班牙语字符 CDA_es.xsl:(西班牙语单词-Empleado guía telefónica在生成的HTML中始终显示为Empleado guÃ-a telefónica) 在前端: function tryPolicySuccess(response) { var encodedDocumen
function tryPolicySuccess(response) {
var encodedDocument = response.document;
var decodedDocument = atob(encodedDocument);
var viewer = $window.open('', '_blank');
viewer.document.open().write(decodedDocument);
}
我已经大量搜索过类似的情况,大多数人认为原因是编码,但是我检查了我的XSL、XML文件几次,并且非常肯定它们都是用UTF-8编码的。我找不到导致我的案件出现问题的任何其他原因,有谁想过这个问题的根本原因吗
谢谢 解决方案: 用b64DecodedUnicode(encodedDocument)替换默认的atob(encodedDocument)如何运行转换,如何查看HTML结果?HTML文档是否通过HTTP加载,服务器是否可以发送一些HTTP内容类型标头,其中包含声明8位编码(如Windows-1252或ISO-8859-1)的字符集参数?谢谢,@MartinHonnen,这是一个RESTful API,我添加了有关转换工作原理的详细信息,有什么问题吗?那么您使用客户端Javascript打开一个新的浏览器窗口/选项卡,然后
文档。写入响应,浏览器错误地显示非ASCII西班牙语字符?您是否检查过浏览器采用哪种编码(例如,在Firefox中使用“查看->文本编码”菜单)?您是否使用atob的方法成功地处理了其他非ASCII字符?是的,我发现atob(encodedDocument)对非ASCII西班牙语字符的解码结果是不可读的。我用中文试过,结果还是看不懂。我很确定文档是用UTF-8编码的,你认为这个错误的原因可能是因为解码吗?浏览器本身可以正常显示非ASCII字符
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:n1="urn:hl7-org:v3"
xmlns:in="urn:lantana-com:inline-variable-data">
<xsl:output method="html" indent="yes" version="4.01" encoding="UTF-8" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN"/>
<xsl:param name="limit-external-images" select="'yes'"/>
<!-- A vertical bar separated list of URI prefixes, such as "http://www.example.com|https://www.example.com" -->
<xsl:param name="external-image-whitelist"/>
<!-- string processing variables -->
<xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<!-- removes the following characters, in addition to line breaks "':;?`{}“”„‚’ -->
<xsl:variable name="simple-sanitizer-match"><xsl:text> "':;?`{}“”„‚’</xsl:text></xsl:variable>
<xsl:variable name="simple-sanitizer-replace" select="'***************'"/>
<xsl:variable name="javascript-injection-warning">WARNING: Javascript injection attempt detected in source CDA document. Terminating</xsl:variable>
<xsl:variable name="malicious-content-warning">WARNING: Potentially malicious content found in CDA document.</xsl:variable>
<xsl:variable name="lang.note" select="'IMPORTANT:'"></xsl:variable>
<!-- global variable title -->
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="string-length(/n1:ClinicalDocument/n1:title) >= 1">
<xsl:value-of select="/n1:ClinicalDocument/n1:title"/>
</xsl:when>
<xsl:when test="/n1:ClinicalDocument/n1:code/@displayName">
<xsl:value-of select="/n1:ClinicalDocument/n1:code/@displayName"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>Clinical Document</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Main -->
<xsl:template match="/">
<xsl:apply-templates select="n1:ClinicalDocument"/>
</xsl:template>
<!-- produce browser rendered, human readable clinical document -->
<xsl:template match="n1:ClinicalDocument">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<xsl:comment> Do NOT edit this HTML directly: it was generated via an XSLT transformation from a CDA Release 2 XML document. </xsl:comment>
<title>
<xsl:value-of select="$title"/>
</title>
<xsl:call-template name="addCSS"/>
</head>
<body class="container-fluid">
<div class="row">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="education-text">
<div>
<!--<strong>IMPORTANT:</strong>-->
<strong><xsl:value-of select="$lang.note"></xsl:value-of></strong>
</div>
<div>Per your share settings, items highlighted in Red are marked for redaction and will
not be shared; they are only shown for review purposes.
Always consult your doctor regarding possible risks and side effects resulting from
your sharing preferences and settings.
</div>
</div>
</div>
</div>
</div>
String segmentedClinicalDocument = new String(dssResponse.getTryPolicyDocument(), StandardCharsets.UTF_8);
Document taggedClinicalDocument = documentXmlConverter
.loadDocument(segmentedClinicalDocument);
String xslUrl = Thread.currentThread().getContextClassLoader().getResource(getCdaXSL()).toString();
String output = xmlTransformer.transform(taggedClinicalDocument, xslUrl, Optional.<Params>empty(), Optional.<URIResolver>empty());
TryPolicyResponse tryPolicyResponse = new TryPolicyResponse();
tryPolicyResponse.setDocument(output.getBytes());
return tryPolicyResponse;
@RequestMapping(value = "/tryPolicyXHTML", method = RequestMethod.GET)
function tryPolicySuccess(response) {
var encodedDocument = response.document;
var decodedDocument = atob(encodedDocument);
var viewer = $window.open('', '_blank');
viewer.document.open().write(decodedDocument);
}
function b64DecodedUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}