I am using XSLT to transform HTML to XSL-FO. The fact that we are transforming from HTML to XSL-FO is probably irrelevant to answering this question.
For several of my values which use concat
for font size and height, the output of concat
is randomly duplicated for a single call.
Example: where the value of $lineheight-td
is 13
for the following code:
<fo:block line-height="{concat($lineheight-td, 'pt')}">
this is the expected correct output that I usually receive:
<fo:block line-height="13pt">
this is incorrect output that I receive ~1% of the time:
<fo:block line-height="13pt13pt">
this is incorrect output that I receive < 1% of the time:
<fo:block line-height="13pt����">
(note how unexpected output is 4 characters ('1'
, '3'
, 'p'
, 't'
) and the unexpected '�'
is produced 4 times).
These duplicate outputs generate from the concat
call in different places from the same input HTML file on different iterations.
My current workaround is to re-transform if we get a bad output; so far this solves the problem, and proves this isn't data-related, but the duplicate output shouldn't be happening in the first place. I'm running under a multi-threaded Java environment, but I'm using a new Transformer
for each individual transformation call, from a shared Template
initialized one time at application start-up.
Why is this happening with concat, and how do I fix it?
The application uses an older Xalan library (2.7.0). I'm going to look into Xalan bugs and upgrading to Xalan 2.7.1 or higher.
Environment:
JBoss 7.2.0
JRE 1.7.0_45
xalan-2.7.0
xml-apis-1.3.04
xml-apis-ext-1.3.04
Java code:
String inputData = ...; // OUR HTML
Templates template = (Templates)templatesMap.get("HTML2FO");
Transformer transformer = template.newTransformer();
StreamSource streamSource = new StreamSource(new StringReader(data));
StringWriter writer = new StringWriter();
transformer.transform(streamSource, new StreamResult(writer));
String outputData = writer.toString(); // OUR FO
答案 0 :(得分:2)
该应用程序使用较旧的Xalan库(2.7.0)。 我将调查Xalan错误并升级到Xalan 2.7.1或更高版本。
Xalan版本发行说明仅列出没有描述的错误号,并且在发布Xalan 2.7.1之后的某个时刻,Xalan开发切换到另一个错误跟踪器。关于他们旧的,&#34;固定&#34;的信息。虫子已经消失了。
没有任何东西&#34;证明&#34;任何给定的库都存在问题,我最终将所有与XML和转换相关的JAR文件更新为以下版本:
JAR FILE NAME VERSION
serializer.jar 2.7.2
xalan.jar 2.7.2
xerxesImpl.jar 2.11.0
xml-apis.jar 1.4.01
xml-apis-ext.jar 1.4.01
使用原始XML库进行~8,000次转换时,我的成功率达到99%;失败的文件在第二次迭代时成功重新处理,这表明问题不在于我的数据。
对于使用更新的XML库进行约11,500次转换,我获得了100%的成功率。
我会继续测试,但是我可以得出结论,更新所有库似乎已经解决了问题。