Solved

XSL: tokenize

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 71
withoutTen challenge 14 88
squareUp  challenge 22 107
sumHeights  challenge 17 61
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 purpose of this article is to demonstrate how we can use conditional statements using Python.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now