Altova Mailing List Archives

Re: [xsl] N : M transformation

From: "J.Pietschmann" <j3322ptm@-------->
Date: 1/28/2003 10:41:00 AM
Bernd Gauweiler wrote:
I have N streams of "input" XML (N > 1), to be transformed into M 
streams of "output" XML (M > 1, M != N).The transformation is complex in 
that data from several input streams might be required to construct a 
single output element.

What is the best strategy for this? I cannot transform the N input 
streams on a one-by-one basis as it seems. I can merge all N input 
streams into a single input streams (maybe with the aid of seperate 
namespaces), but will a single transformation, applied to a single input 
stream, allow for the creation of multiple output documents simultaneously?

There are several options.
1. Extensions
Most XSLT processors have an extension to redirect the
transformation result to a specific file or URL. You can use
such extensions to create more than one result from a single
transformation. Consult the documentation of your processor for
details of this extension. Usually it is an element called
redirect, write, output or something similar.
2. Use XSLT 2.0 (experimental)
you can use the proposed xsl:result-document element to
redirect the output. The only implementation I know of is
Saxon 7. The advantage compared to a processor specific
extension is, hopefully, portability once XSLT 2.0 becomes
a standard.
3. Text tools
You can generate a single result and use some text processing tool
like Perl, AWK or certain stream editors to split it afterwards.
This is easy if you can arrange your processing so that the
result is written in order, for example
 @file 1.xml
 @file 2.xml
Perl and AWK can also deal with more complicated scenarios. Of
course, using magic strings is not bulletproof and may produce
a long term risk.

You can access more than one XML source by using the document()
function. You can declare one of your sources the "master source"
and access the other N-1 input through document() from the style
sheet, or you can use an XML document containing the names of the
documents to access and use document() to pull them in.
Alternatively, you can use XInclude (if you have an XInclude
processor), XML entities, like
    <!ENTITY file1 SYSTEM "file1.xml"> ...
  <root>&file1; ...</root>
or Perl, AWK and many other text tools to achive for aggregation
before the XSLT processing


XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.