Solved

XSL: tokenize

Posted on 2006-06-29
2
726 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
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.

691 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