Lets say I want to write text outputs from many xmls having following format.
And some of these xml files may not have values for the nodes [name , age , school].
<student>
<name>Dilruk</name>
<age/>
<school>abc</school>
</student>
All these xml files are located in one directory and i traverse them to generate output files per each xml.
So basically i am using one xsl file iu am having and trying to generate outputs by considering these xml files of similar format [with different node values].
But i only need to write corresponding outputs to the xml files which are having a certain condition. [lets say having a name, because some xml files doesn,t contain name value].
So if i am having 5 xml files to transform and out of which only 3 files are having non empty name values i want to generate only 3 output files of those.
I prefer a solution from XSL side which i know most unlikely, But if we can do this without reading the contents of the output files and deleting them or deleting them according to the size [0kB] in java side, its really helpful too.
Thanks in advance :)
In XSLT 1.0, without vendor-specific extensions, it is not possible to produce multiple outputs at the style-sheet level. Depending on what XSLT 1.0 engine you are using, there are extensions to enable multiple ouput, and I have put some links to some of these below. As an alternative, you might consider getting your client to invoke the style-sheet multiple times, once per input file.
As for XSLT 2.0, the approach that I would take would be:
- Supply to the style-sheet, a space separated list of input file names as a parameter.
- For file-name open it as a document
- For each of these with a name node, use xsl:result-document and a template to copy to an output file whose file name is based on the input file name.
For example style-sheets (XSLT 2.0), see:
- http://www.ibm.com/developerworks/xml/library/x-tipmultxsl/index.html
- Using XSLT to output multiple files
For XSLT 1.0, Microsoft case, see:
- http://msdn.microsoft.com/en-us/library/ms950784.aspx (scroll down to Example: Invoice Processing)
For XSLT 1.0, XALAN case, see:
- http://www.abbeyworkshop.com/howto/xslt/xslt_split/index.html; or
- http://www.stylusstudio.com/xsllist/200108/post50930.html
Also see related question:
- XSLT split output files - muenchian grouping