You don't say whether the elements to go in each output file are adjacent in the input, or whether they are scattered around. If they are scattered, then this is a pretty tough problem that's probably beyond what Saxon 9.4 can do in streaming mode.

If they are adjacent, then it's still difficult, because Saxon 9.4 doesn't yet support streamed group-adjacent, but I think it can probably be done, with a little bit of supporting Java code, by taking advantage of the xsl:iterate instruction. The trick is to use xsl:iterate to iterate over all the main-prod and sub-prod elements, using the xsl:iterate parameter to keep track of the current grouping key, and when the key changes, emit something like a <?start-new-file?> processing instruction. You then need to intercept these markers in the serialization pipeline. This isn't as complicated as it sounds:

Write a class MySerializerFactory that extends net.sf.saxon.lib.SerializerFactory with:

protected Emitter newXMLEmitter(Properties properties) {
  return new XMLEmitter() {
    public void processingInstruction (String target, CharSequence data, int locationId, int properties)
        throws XPathException  {
       if (target.equals("start-new-file") {
         endElement();
         endDocument();
         writer.close();
         writer = new FileWriter(.....);
         openDocument();
         startElement(.....);
       } else {
        super.processingInstruction(target, data, locationId, properties);
       }
   }
}

and then register this using configuration.setSerializerFactory().

Michael Kay
Saxonica

On 10/05/2012 11:03, Kunal Chauhan wrote:
Hi,
 
I want to divide xml in following way.
 
this is my xml file
 
<product>
 <main-prod id='01'>Stationary </main-prod>
 ...
 ...
 <sub-prod category='01'>Pen</sub-prod>
 <sub-prod category='01'>Pencil</sub-prod>
</product>
 
i want to create seprate xml file which contains same id and category value.
for eg. in this example main-prod and sub-prod elements comes as an output because each have id and category '01'.
 
So, this way i want to split large xml file.

On Thu, May 10, 2012 at 2:38 PM, Michael Kay <mike@saxonica.com> wrote:
Well, it rather depends on what processing you want to do with the file.

Have you read the documentation on streaming:

http://www.saxonica.com/documentation/sourcedocs/streaming.xml

and on document projection:

http://www.saxonica.com/documentation/sourcedocs/projection.xml

Getting streaming to work can be tricky; you're at the bleeding edge where the specs are still working drafts and Saxon's implementation of them is partial. But I'm happy to give advice (on-list or off) if you need help.

Michael Kay
Saxonica


On 10/05/2012 07:10, Kunal Chauhan wrote:

Hi,
 
I want to process an XML file which is 4 GB in size.
I am using saxonEE library for that.
can any one help me out what should be my approch for that ?
 
Thanks,

--
Kunal Chauhan
[+918655517141]
[+919904983614]



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--
Kunal Chauhan
mail4ck@gmail.com
[+918655517141]
[+919904983614]



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help