File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Xslt tokenize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Xslt tokenize " Watch "Xslt tokenize " New topic

Xslt tokenize

Johan Lijffijt

Joined: Feb 17, 2013
Posts: 1
Hello is it possible to use xslt to go from


To this


Any help would be most appreciated.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I don't see why not. I assume your problem lies in breaking the (badly-designed) text nodes into pieces based on the semicolon delimiters?

What I would do is first to count the number of pieces in both of the nodes. If those numbers aren't the same then I would exit with an error message.

Then I would do a loop where K runs from 1 to N, where N was the number of pieces, extract the Kth piece from each of the text node, and output a suitable <LINE> element with that data.

If your problem is now that you don't know how to do any of those loops in XSLT, the way to do a loop in XSLT is usually via a recursive template. For example here's pseudocode for counting the number of pieces of a semicolon-delimited string:

Does that help you get started?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 630
[1] First you should not use tag name starting with xml or any combination of upper/lower case of the 3 letters. It is reserved by the recommendation. However, most/all parsers are very pardonning in this regard. But you should still try not to name tag that way which is not asking too much.

[2] I guess you should do that with xslt 1.0 if you are novice in xslt. The breaking string up into tokens are done through some recursive call of template to itself. I can show you how.

It is as simple if you are not familiar with the idiosyncrasy of functional programming. If you have doubts, you should break it up studying its components yourself.
I agree. Here's the link:
subject: Xslt tokenize
It's not a secret anymore!