This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: regd String Tokeniser


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]