?
Solved

XSL: tokenize

Posted on 2006-06-29
2
Medium Priority
?
731 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

762 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