Solved

XSL: tokenize

Posted on 2006-06-29
2
716 Views
Last Modified: 2013-11-18
Hi Gertone,
is there a way to tokenize a given String, seperated by e.g. ';'???
If I have a XSL variable $output with content 'c:\test;d:\test2...', I want to loop each of these entries.
Ciao
0
Comment
Question by:go4java
  • 2
2 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17009581
Hi go4java,

You need to deal with this recursively
- pass the string to a template
- deal with the substring-before the ;
- pass the part behind the ; to the same template, until you are done

I ll draft you an example in a second

Cheers!
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 17009643
go4java,

put your string in a <test> element and use this
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="test">
        <xsl:call-template name="handlePart">
            <xsl:with-param name="part" select="."/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="handlePart">
        <xsl:param name="part"/>
        <xsl:choose>
            <xsl:when test="contains($part, ';')">
                <xsl:value-of select="substring-before($part, ';')"/><!-- do something with the part here -->
                <xsl:call-template name="handlePart">
                    <xsl:with-param name="part" select="substring-after($part, ';')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$part"/><!-- do something with the part here -->
             </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 97
Re-position the objects 7 110
Post xml via PHP Soap Client 3 49
XSL FO - text wrapping and empty spaces 1 35
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question