Altova StyleVision 2025 Professional Edition

If access is via a class file, then there are four possibilities:

 

The class file is in a package. The XSLT or XQuery file is in the same folder as the Java package. (See example below.)

The class file is not packaged. The XSLT or XQuery file is in the same folder as the class file. (See example below.)

The class file is in a package. The XSLT or XQuery file is at some random location. (See example below.)

The class file is not packaged. The XSLT or XQuery file is at some random location. (See example below.)

 

Consider the case where the class file is not packaged and is in the same folder as the XSLT or XQuery document. In this case, since all classes in the folder are found, the file location does not need to be specified. The syntax to identify a class is:

 

         java:classname

 

 where

 

java: indicates that a user-defined Java function is being called; (Java classes in the current directory will be loaded by default)

         classname is the name of the required method's class

 

The class is identified in a namespace URI, and the namespace is used to prefix a method call.

 

Class file packaged, XSLT/XQuery file in same folder as Java package

The example below calls the getVehicleType()method of the Car class of the com.altova.extfunc package. The com.altova.extfunc package is in the folder JavaProject. The XSLT file is also in the folder JavaProject.

 

 <xsl:stylesheet version="2.0" 

         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 

         xmlns:xs="http://www.w3.org/2001/XMLSchema" 

         xmlns:fn="http://www.w3.org/2005/xpath-functions"

         xmlns:car="java:com.altova.extfunc.Car" >

 <xsl:output exclude-result-prefixes="fn car xsl fo xs"/>

 

 <xsl:template match="/">

            <a>

    <xsl:value-of select="car:getVehicleType()"/>

    </a>

 </xsl:template>

 

 </xsl:stylesheet>

 

Class file referenced, XSLT/XQuery file in same folder as class file

The example below calls the getVehicleType()method of the Car class. Let us say that: (i) the Car class file is in the following folder: JavaProject/com/altova/extfunc, and (ii) that this folder is the current folder in the example below. The XSLT file is also in the folder JavaProject/com/altova/extfunc.

 

 <xsl:stylesheet version="2.0" 

         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 

         xmlns:xs="http://www.w3.org/2001/XMLSchema" 

         xmlns:fn="http://www.w3.org/2005/xpath-functions"

         xmlns:car="java:Car" >

 <xsl:output exclude-result-prefixes="fn car xsl fo xs"/>

 

 <xsl:template match="/">

            <a>

    <xsl:value-of select="car:getVehicleType()"/>

    </a>

 </xsl:template>

 

 </xsl:stylesheet>

 

Class file packaged, XSLT/XQuery file at any location

The example below calls the getCarColor()method of the Car class of the com.altova.extfunc package. The com.altova.extfunc package is in the folder JavaProject. The XSLT file is at any location. In this case, the location of the package must be specified within the URI as a query string. The syntax is:

 

         java:classname[?path=uri-of-package]

 

 where

 

java: indicates that a user-defined Java function is being called

uri-of-package is the URI of the Java package

classname is the name of the required method's class

 

The class is identified in a namespace URI, and the namespace is used to prefix a method call. The example below shows how to access a class file that is located in another directory than the current directory.

 

 <xsl:stylesheet version="2.0" 

         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

         xmlns:xs="http://www.w3.org/2001/XMLSchema" 

         xmlns:fn="http://www.w3.org/2005/xpath-functions"

         xmlns:car="java:com.altova.extfunc.Car?path=file:///C:/JavaProject/" >

 

 <xsl:output exclude-result-prefixes="fn car xsl xs"/>

 

 <xsl:template match="/">

            <xsl:variable name="myCar" select="car:new('red')" /> 

    <a><xsl:value-of select="car:getCarColor($myCar)"/></a>

 </xsl:template>

 

 </xsl:stylesheet>

 

Class file referenced, XSLT/XQuery file at any location

The example below calls the getCarColor()method of the Car class. Let us say that the Car class file is in the folder C:/JavaProject/com/altova/extfunc, and the XSLT file is at any location. The location of the class file must then be specified within the namespace URI as a query string. The syntax is:

 

         java:classname[?path=<uri-of-classfile>]

 

 where

 

java: indicates that a user-defined Java function is being called

uri-of-classfile is the URI of the folder containing the class file

classname is the name of the required method's class

 

The class is identified in a namespace URI, and the namespace is used to prefix a method call. The example below shows how to access a class file that is located in another directory than the current directory.

 

 <xsl:stylesheet version="2.0" 

         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

         xmlns:xs="http://www.w3.org/2001/XMLSchema" 

         xmlns:fn="http://www.w3.org/2005/xpath-functions"

         xmlns:car="java:Car?path=file:///C:/JavaProject/com/altova/extfunc/" >

 

 <xsl:output exclude-result-prefixes="fn car xsl xs"/>

 

 <xsl:template match="/">

            <xsl:variable name="myCar" select="car:new('red')" /> 

    <a><xsl:value-of select="car:getCarColor($myCar)"/></a>

 </xsl:template>

 

 </xsl:stylesheet>

 

Note:When a path is supplied via the extension function, the path is added to the ClassLoader.

 

© 2018-2024 Altova GmbH