Skip to Content
0
Former Member
Apr 20, 2010 at 04:38 PM

XSLT Enhancement with Java, Tokenize Functionality

131 Views

I tried the following requirement using EXSLT with no luck. Is there any other alternative to tokenize in XSLT 1.0.

The syntax i have here is

<xsl:for-each select="tokenize($this/Field1,',')">

<xsl:variable name="f1v" select="."/>

<xsl:for-each select="tokenize($this/Field2,'\|')">

<xsl:variable name="f2v" select="."/>

<xsl:for-each select="tokenize($this/Field3,'\|')">

<xsl:variable name="f3v" select="."/>

There are multiple for-each based on tokens

I am leaning towards to Enhancing XSLT with Java Function. As i have less experience with Java, can anybody help me with the code that can be used by XSLT for Tokenize functionality.

I have written something like following. I still have errors to fix. But i am not sure about having resultSet or return at the end, to make sure all the tokens were sent to XSLT.

public class MyStringToken

{

public static void main(String [] args)

{

String str = "sssd;wwer;ssswwwwdwwwwwwwwwww;wwwwe";

String delimiter = ";";

MyStringToken my = new MyStringToken();

my.getTokens(str,delimiter);

}

public void getTokens(String str,String delimiter)

{

StringTokenizer st = new StringTokenizer(str,delimiter);

while(st.hasMoreElements())

{

try

{

String delString = new String(st.nextElement().toString());

return (delString);

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

Any help is appreciated