Subject: Re: [xsl] regd String Tokeniser From: "Carsten Klein" <carstenklein@xxxxxxxx> Date: Mon, 15 Apr 2002 13:55:24 +0200 |
Hi, I read something about the StringTokenizer class and, by having a look at the source of StringTokenizer class I can tell you that there is no toString() method which may leave you with string containing your tokens, nor does it return a nodeset readily to use by the xsl processor. Instead you will need to write an extension function called by xsl to tokenize the string and return it as an string, delimited by whatever delimiters you want to have, for example a colon or else. e.g. <xsl:variable name="tokens" select="myExt:tokenize($string)"/> In this function myExt:tokenize() you may convert the tokens contained in the string to a nodeset, your favorite xsl processor may use directly (preferred) or a string containing the tokens delimited by colon or else, which then needs to be parsed by a recursive template. public String tokenize(String str) { const DELIMITER = ","; StringTokenizer s = new StringTokenizer(str); String o = ""; while (s.hasMoreTokens()) { o += s.nextToken + DELIMITER; } return(o); } How to implement such a Java extension and use it in your environment, see the specifications of the processor you are using. Don't forget to include the myExt namespace to the declaration of your stylesheet. Then you may parse this result using a recursive template like this, passing in the variable containing the tokenized string. <xsl:template name="parseTokens"> <xsl:param name="tokens"/> <!-- do nothing if $tokens is empty --> <xsl:if test="string-length($tokens)!=0"> <!-- output first token in list --> <xsl:value-of select="substring-before($tokens, ',')"> <!-- call parseTokens with the remainder of the tokens --> <xsl:call-template name="parseTokens"> <xsl:with-param name="tokens" select="substring-after($tokens, ',')"/> </xsl:call-template> </xsl:if> </xsl:template> Hope this may suit your needs Bye Carsten _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] regd String Tokeniser, cutlass | Thread | Re: [xsl] regd String Tokeniser, Li, Carsten Klein |
Re: [xsl] regd String Tokeniser, cutlass | Date | Re: [xsl] regd String Tokeniser, Li, Carsten Klein |
Month |