How to Make a Call to Java From XSL

An XSL stylesheet is a file that lets you customize and lay out XML documents in a Web page or on a desktop application. The XSL document has several extended features and one of those features is to call a Java method, which is a function located in a Java class. You must first point to the Java class that contains the method you want to call, then you can call the method within the body of the XSL stylesheet.

Instructions

    • 1

      Right-click the XSL document you want to edit and select "Open With." Choose your XSL editor you want to use to add the Java method.

    • 2

      Add the Java package inclusion directive in the main definition section of the XSL sheet. The definition of the file is the very first tag definition. Add the following code to the tag:

      xmlns:str="xalan://org.apache.commons.lang.StringUtils"

      In this example the Java "StringUtils" class is included. Change the class with the class name that contains the method you want to use.

    • 3

      Add the call to the method in the body of the XSL sheet. For instance, if you want to change a customer name to all uppercase characters the following XSL tag uses the "uppercase" Java method:

      <xsl:value-of select="str:upperCase(string(CustomerName))"></xsl:value-of>

Related Searches:

References

Comments

Related Ads

Featured