In general, for XML conversion processing we can use XSLT to process, so that we can extract the necessary information in the XML message generation into the format of the report we need, such as the XML data to automate the filtering of some information generated text TXT file report, csv,html,pdf and other reports. But sometimes XSLT is not particularly flexible, at least, and sometimes without Java code, it is convenient and flexible to manipulate XML directly.
So, we need to be able to use XSLT and Java code together.
Declare the necessary prefixes and bind the Java class as follows, binding the Java.lang.Math class in the XSLT.
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" xmlns:math= "http// www.math.org/"> <xsl:script implements-prefix=" math "language=" java "src=" Java:java.lang.Math "/> ...</xsl:stylesheet>
Here's how to use the Min method of the Java math le species
<xsl:template name= "Test" > <value-of select= "Math:min (101)"/> </xsl:template>
In XSLT we can also construct objects, taking the following example
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" xmlns:math= "http// www.date.org/"> <xsl:script implements-prefix=" date "language=" java "src=" Java:java.util.Date "/> <xsl:template name= "Test" > <variable name= "date" select= "date:new ()"/> <value-of Select= "date:tostring ($date)"/> </xsl:template></xsl:stylesheet>
Pass parameters to the Java object as shown below
<xsl:template name= "Test" > <value-of select= "math:min (number (@value1), number (@value2))"/> </xsl:template>
XSLT and Java Integration Common technical key points