cancel
Showing results for 
Search instead for 
Did you mean: 

XLST with Java enhancement

Former Member
0 Kudos

Givent the following java code:

class myClass {

static int num=0;

static public int getNum() {

++ num;

return num;

}

}

If I call getNum() in XSL as follows

<xsl:value-of select="Java:myCLass.getNum()"/>

<xsl:value-of select="Java:myCLass.getNum()"/>

is the result:

1, 2

or

1, 1?

I want to ouput 1,2, if not, how can I do?

I can not test in sap now ,hence post this thread, thanks.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

close this

Former Member
0 Kudos

If I remember correctly, ++num will first increment value and THEN assign it to num ... num ++ will assign the value and THEN increment it (available for next time) ...

In your case, it should output 1, 2 etc ! Why not using static int num = 1; and num++; ?

Hope this helps

Chris

Edited by: Christophe PFERTZEL on Sep 28, 2009 4:22 PM

Former Member
0 Kudos

thanks.

Well, no matter ++num or num ++.

My point is if num value can being passed through multiple java calls in the transformation.

I mean when each time XSLT call the java method, the XSLT processor init a new process or there is just one process.

If is new process, then we can not view value changes from different java method.

It's fine to hear that it output 1,2 , which is what I want. That means, XSLT just use one process------

And XSLT only can call static java method?

Or it can call the non static methods like: ?

<xsl:variable name="obj" select="java:myClass.new()"/>

<xsl:variable name="test" select="java:obj.xxxx()"/>