2.7.1to work compatible with
Xalan-Javais an XSLT processor for transforming XML documents into HTML, text, or other XML document types.
The issues that need to fix while upgrade XSL to work with JDK 1.6 and Xalan 2.7.1 will be discussed here and in this post we will look in to sample examples that help us to create XSL’s to work compatible with these new version.
Please note that the problems identified here work well with JDK 1.5. Therefore, these changes require only, if we want our XSL to parse successfully with JDK 1.6.
xsl:transform. It should not appear in the end or middle of the stylesheet. Otherwise it throws exception
“Error! xsl:import is not allowed in this position in the stylesheet!”
For example, the code
“Fatal Error! java.lang.RuntimeException: ElemTemplateElement error: xsl:template requires either a name or a match attribute.”
The below code will execute successfully.
For example, the code
will throw exception
“Error! xsl:value-of is not allowed in this position in the stylesheet!”
XSL Code such as
java.lang.IllegalArgumentException: argument type mismatch and
The reason is that the
org.apache.xalan.extensions.MethodResolverpicks a method whose argument types are not converted properly. This was noticed in the new versions of JVM due to the order at which they return all methods available for a given class and the issue is still not resolved yet.
Further information can be refer to
I have replaced StringBuilder with Map to correctly transform the XSL.
, CASE WHEN .
IS NULL THEN
Value exist in Map =
At this point, we might expect
java:containsKey($processedMap,$temp_core_alias_value)to return true and the output of the above as
“Value exist in Map = Test Value”But when transform using Xalan-Java 2.7.1, the Map return false and therefore no output appear.
The reason is that the evaluating expression for the
temp_core_alias_valuevariable would return
org.apache.xml.dtm.ref.DTMNodeIterator@e020c9 and therefore, the
containsmethod of the
Mapwould always return false regardless of the key present.
We can transform
DTMNodeIteratorto normal String form by concatenate an empty string with
temp_core_alias_valuevariable like the following
Adding this line right before put in to the Map would result in the normal expected output.