aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Xslt tokenize " Watch "Xslt tokenize " New topic
Author

Xslt tokenize

Johan Lijffijt
Greenhorn

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

Code:

To this

Code:

Any help would be most appreciated.

Johan
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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: 535
    
    3
[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: http://aspose.com/file-tools
 
subject: Xslt tokenize