Altova XMLSpy 2024 Professional Edition

If access is via a JAR file, the URI of the JAR file must be specified using the following syntax:

 

         xmlns:classNS="java:classname?path=jar:uri-of-jarfile!/"

         

The method is then called by using the prefix of the namespace URI that identifies the class: classNS:method()

 

 In the above:

 

java: indicates that a Java function is being called

classname is the name of the user-defined class

? is the separator between the classname and the path

path=jar: indicates that a path to a JAR file is being given

uri-of-jarfile is the URI of the jar file

!/ is the end delimiter of the path

classNS:method() is the call to the method

 

 

Alternatively, the classname can be given with the method call. Here are two examples of the syntax:

 

         xmlns:ns1="java:docx.layout.pages?path=jar:file:///c:/projects/docs/docx.jar!/"

         ns1:main()                

 

         xmlns:ns2="java?path=jar:file:///c:/projects/docs/docx.jar!/"

         ns2:docx.layout.pages.main()

 

Here is a complete XSLT example that uses a JAR file to call a Java extension function:

 

 <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?path=jar:file:///C:/test/Car1.jar!/" >

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

 

 <xsl:template match="/">

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

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

 </xsl:template>

 

 <xsl:template match="car"/>

 

 </xsl:stylesheet>

 

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

 

© 2017-2023 Altova GmbH