passing variables frm xsl to a java method

here is my current frustration -- aside from being new to java and xsl...

i have an xml message (that is passed to me from another process) as follows:

<?xml version="1.0" encoding="UTF-8"?>

<WillsXMLStart>

<inputEventStart>TRUE</inputEventStart>

<inputEventNumber>1</inputEventNumber>

<inputEventID>HEREISTHEID</inputEventID>

<inputEventEnd>TRUE</inputEventEnd>

</WillsXMLStart>

ok now i am using netbeans to create and xsl to gram the information and reformat the information because the end process want the data and event tags differantly. my xsl is as follows:

<?xml version="1.0" encoding="UTF-8" ?>

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

xmlns:gng="java:GetAndConvert"

exclude-result-prefixes="gng"

version="2.0">

<xsl:outputencoding="UTF-8" indent="yes" method="xml"/>

<xsl:template match="/">

<WillsXMLStart>

<inputEventStart>

<xsl:value-of select="WillsXMLStart/inputEventStart"/>

</inputEventStart>

<inputEventNumber>

<xsl:value-of select="WillsXMLStart/inputEventNumber"/>

</inputEventNumber>

<inputEventID>

<xsl:variable name="inputVariable">

<xsl:value-of select="WillsXMLStart/inputEventID"/>

</xsl:variable>

<!-- <xsl:value-of select="$inputVariable"/> -->

<xsl:value-of select="gng:getString('$inputVariable')"/>

</inputEventID>

<inputEventEnd>

<xsl:value-of select="WillsXMLStart/inputEventEnd"/>

</inputEventEnd>

</WillsXMLStart>

</xsl:template>

</xsl:stylesheet>

ok... now for the frustrating part... what i need to do is (as the code shows(i think)), get and store in a variable called "inputVariable" the specific informati that is stored in the "inputEventID" from the xml. that works fine... but i need to pass that information as a string to the java method "getString(String inputVariable)".... my java code (just a test) is as follows:

/*

* GetAndConvert.java

*

* @author william

* Created on June 27, 2007, 8:04 AM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

publicclass GetAndConvert{

/** Creates a new instance of GetAndConvert */

public String getString(String inputVariable){

String x ="test";

System.out.print("this is the string that is hardcoded into GAC: " + inputVariable);

return x;

}

}

OK.... i am getting the following error when i try to run the whole thing -- translation from within XSL:

XML validation started.

Checking file:/home/william/PROGRAMMING/TestingJavaXML/src/testingXML-JavaInput.xsl...

Cannot findclass'java:GetAndConvert'.

Cannot find external method'java:GetAndConvert.getString' (must bepublic).

Could not compile stylesheet

i have 2 packages in my "project". 1 = default where i have my xml and xsl files... 2 = JavaEvents where i have my .Java file.

any and all help would really be appreciated... as i am going bald trying to figure this out. you can either post here or you can email me at: william.gray@thermofisher.com

thanks in advance for all your help.

Deathsbain.

[4487 byte] By [Deathsbaina] at [2007-11-27 9:01:25]
# 1

either make your java method static... or do following

...

<xsl:variable name="myInstance" select="gng:new()"/>

<xsl:value-of select="gng:getString($myInstance, $inputVariable)"/>

try it.

yue42a at 2007-7-12 21:30:59 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
wow... that worked perfectly... we just hired 3 java programmers and all of them said that they would never thought of doing it that way... but now that they see it... it makes perfect sense...THANK YOU SOOOOOOOOOOO MUCH!!!!!Deathsbain.
Deathsbaina at 2007-7-12 21:30:59 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

You are welcome. Don't tell me you hired 3 Java programmers to do this:)

Well, this is not so much a Java problem but XSL problem.

I personally do not like how XSL handles instance Java call, that you have to pass the instance as the first variable. It is quite confusing, i guess that is how they decide to reflection behind the scene.

Anyway, happy it worked out. Good luck!

yue42a at 2007-7-12 21:30:59 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

no we hired java programmers because the company that created our GUI quit, and we still have to support the sw... and de-bugg it....

but once again ... thanks a million for your help... the java guys wanted to create their own parser and things for the incoming xml would have taken weeks...

Deathsbaina at 2007-7-12 21:31:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

OK... now i am getting this error...:

XSL

<!--

Document: translatorJavaXSL.xsl

Created on : June 27, 2007, 3:53 PM

Author: william

Description:

Purpose of transformation follows.

-->

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

xmlns:gng="java:JavaSRC.xmljavamain"

exclude-result-prefixes="gng"

version="1.0">

<xslutput encoding="UTF-8" indent="yes" method="xml"/>

<xsl:template match="/">

<WillsInputXML>

<eventStart>

<xsl:value-of select="WillsInputXML/eventStart"/>

</eventStart>

<eventNumber>

<xsl:value-of select="WillsInputXML/eventNumber"/>

</eventNumber>

<eventUniqueID>

<xsl:variable name="inputVariable">

<xsl:value-of select="WillsInputXML/eventUniqueID"/>

</xsl:variable>

<xsl:value-of select="$inputVariable"/>

<xsl:variable name="myInstance">

<xsl:value-of select="gng:new()"/>

</xsl:variable>

<xsl:value-of select="gng:xmlJavaConverter($myInstance, $inputVariable)"/>

</eventUniqueID>

<eventEnd>

<xsl:value-of select="WillsInputXML/eventEnd"/>

</eventEnd>

</WillsInputXML>

</xsl:template>

</xsl:stylesheet>

JAVA

/*

* xmljavamain.java

*

* Created on July 2, 2007, 8:58 AM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package javaSRC;

/**

*

* @author william

*/

public class xmljavamain

{

/** Creates a new instance of xmljavamain */

public String xmlJavaConverter (String inputValue)

{

return ("this is the xmljavamain function...");

}

}

when running the "NetBeans" translator for the XSL page i get this error.

XML validation started.

Checking file:/home/william/PROGRAMMING/XML-Java-XSL/src/xmljavaxsl/translatorJavaXSL.xsl...

Cannot find class 'java:JavaSRC.xmljavamain'.

Cannot find external constructor 'java:JavaSRC.xmljavamain'.

The first argument to the non-static Java function 'xmlJavaConverter' is not a valid object reference.

Could not compile stylesheet

Could not compile stylesheet

XML validation finished.

WHAT AM I DOING WRONG?

Deathsbain.

Deathsbaina at 2007-7-12 21:31:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Just reading your error message:Cannot find class 'java:JavaSRC.xmljavamain'.Cannot find external constructor 'java:JavaSRC.xmljavamain'make sure the JavaSRC.xmljavamain is in your classpath.
yue42a at 2007-7-12 21:31:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...