Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xslt tokenize

 
Johan Lijffijt
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello is it possible to use xslt to go from

Code:

To this

Code:

Any help would be most appreciated.

Johan
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic