RE: [xsl] Splitting multiple node occurrences into separate xmls

Subject: RE: [xsl] Splitting multiple node occurrences into separate xmls
From: "Vishwajit Pantvaidya" <pantvaidya@xxxxxxxxxxx>
Date: Thu, 28 Apr 2005 15:40:28 -0700
Thanks for your reply, Aaron.

Vishwajit, parsing a string containing XML into XML elements is functionality provided by some parsers; see eval() functions. Generating multiple outdocuments from a single input is also extended functionality provided by some processors.

Actually my example was probably too simplistic. The source xml may not have the "a" nodes (mentioned in my earlier post) exactly as they need to be in the o/p - so it needs to be transformed resulting in the generation of the "a" nodes. So the transformation is not just to split those "a" nodes.
I checked out xalan and it does not seem to support multiple o/p docs. Can you let me know which processor does?


If you don't want to use the multiple-document extension, and don't care about processing efficiency (though from prior posts you do seem to want to keep tabs on that metric), one approach to splitting

You observed right. Efficiency is important - currently I am doing the transformation and letting all the "a" nodes remain in the output xml. I get the output as a DOMResult (thereby hopefully leveraging the internal result tree created by xalan) and then parse the DOM to isolate each "a" occurrence. Most of the "a" nodes would be children of the root - so not too much traversal. I could have used xalan XPath API instead but it seems to come with its own baggage. DOM itself does not seem to offer a way to serialize a node to xml. So either I use the xerces DOMSerializer or use the transformer to do it - I chose the latter, as the former seems to be more for pretty printing.



Thanks and regards,


Vishwajit.



From: "Vishwajit Pantvaidya" <pantvaidya@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Splitting multiple node occurrences into separate xmls
Date: Thu, 28 Apr 2005 12:58:01 -0700

I need to do a transformation that will take an input xml string in a format that is something like
...<a>1</a><a>2</a><a>3</a><a>4</a>...
and apart from transforming it, will split the multiple node occurrences for "a" into different xml's i.e.
xml[1]=<a>1</a>
xml[2]=<a>2</a>...


I was thnking that if xsl offers some kind of looping facility, that may help. But then xsl transformation presumably being single-input, single-output process, just an xsl maynot by itself suffice. Is there a possibility that somehow I can have a java loop pass a looping variable into the xsl-sheet, so that the first transformation gives me the first occurrence of "a", and so on.

Another approach could be to let the xsl transformation return a single xml that has the multiple "a" occurrences and then subsequently seperate them out by carrying out XPath/DOM operations on the transformed xml.

_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Current Thread