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

1
  • What version of XSLT, and what engine are you using? Commented May 31, 2012 at 3:16

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.