XSLT and Java Integration Common technical key points

Source: Internet
Author: User
Tags xsl xslt

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.