0

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 :)

Dilruk
  • 379
  • 5
  • 8

1 Answers1

0

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:

  1. Supply to the style-sheet, a space separated list of input file names as a parameter.
  2. For file-name open it as a document
  3. 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:

For XSLT 1.0, Microsoft case, see:

For XSLT 1.0, XALAN case, see:

Also see related question:

Community
  • 1
  • 1
Sean B. Durkin
  • 12,659
  • 1
  • 36
  • 65