GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes split multi-value XML nodes 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 "split multi-value XML nodes" Watch "split multi-value XML nodes" New topic
Author

split multi-value XML nodes

Edward Chalk
Greenhorn

Joined: May 27, 2014
Posts: 4
Hi everyone,

I have xml that looks like this:

<ORDER>
<CUSTNAME>JULIAN SMITH</CUSTNAME>
<ITEMS>RICE CRISPIES,CORNFLAKES</ITEMS>
<QUANTITIES>1,2</QUANTITIES>
</ORDER>

I need an XSLT to transform this to:
<ORDER>
<CUSTNAME>JULIAN SMITH</CUSTNAME>
<ITEMS>
<ITEM>
<ITEMNAME>RICE CRISPIES</ITEMNAME>
<QUANTITY>1</QUANTITY>
</ITEM>
<ITEM>
<ITEMNAME>CORNFLAKES</ITEMNAME>
<QUANTITY>2</QUANTITY>
</ITEM>
</ITEMS>
</ORDER>

So I need to do 2 actions;
- split the CSV delimited node to multiple actions
- reassign the split values to nodes grouped by the parent ITEM

Thanks :-)
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 520
    
    3
Since you have posted nothing about what you have so far, I can only point you to the use of strings operation generally used to resolve such kind of problem, in particular, the use of substring-before(), substring-after() together with the use of named template and resursive template call. This is a page amongst many you may find useful:
http://www.dpawson.co.uk/xsl/sect2/N1755.html
 
GeeCON Prague 2014
 
subject: split multi-value XML nodes