[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] N : M transformation


Subject: Re: [xsl] N : M transformation
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Tue, 28 Jan 2003 21:42:04 +0100

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. Output 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 <result1> .... </result1> @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.

Input
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
  <!DOCTYPE [
    <!ENTITY file1 SYSTEM "file1.xml"> ...
  ]>
  <root>&file1; ...</root>
or Perl, AWK and many other text tools to achive for aggregation
before the XSLT processing

HTH
J.Pietschmann


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords