xsl-list
[Top] [All Lists]

Re: XML to XML transformation

2003-04-14 12:29:08
Simon Kelly wrote:
I have been looking throught the xslt-cookbook to try to work out the best
was of turning an flat XML document, in to quite a deep complex document.
But I am having a couple of problems working out what it the best way of
doing this in xsl.

The flat structure is an output from a relational db, using ROWSET, ROW then
$column-name as the child node identifiers.

You mean you have something like this?

<DATA>
  <ROWSET>
    <ROW>
      <Id>123</Id>
      <GivenName>Jane</GivenName>
      <FamilyName>Doe</FamilyName>
    </ROW>
    ...
  </ROWSET>
  ...
</DATA>

What's your definition of deep and complex, i.e. what is an example of the
XML you want in your output, given the above input?

However, I will be keeping none of the node names in the new structure,
and I want xsl to create a new document and not a string output.
I am using the javax.xml.transform.Transformer.

In XSLT, you create a new document in the form of an XPath node tree that is
similar to a DOM Document object. Typically, this "result tree" is serialized
as an encoded string after construction, but different XSLT processors offer
alternative types of output, including DOM Document objects. Processors that
implement JAXP may support the DOMResult class, which you can create an
instance of to be the destination for the result tree. You pass this instance
as the second argument to the Transformer's transform() method. Read more about
DOMResult in the javax.xml.transform docs. Your XSLT processor probably comes
with examples demonstrating its usage.

When constructing the new result tree, you are free to create any nodes you
want, and to traverse any part of the source tree, starting at the root node.
Your new elements and attributes can be given any names you want; there's no
obligation to copy the input, or to even base anything on the input at all.

I also need the transform to be very quick, as the relational document size
can be in excess of 4MB.

This will be more of a problem. Very large input files are difficult to
process because some nuances of XSLT require that the document be cached and
operated on with the entire document being in memory at once. There are
various ideas for working around this, including using a SAX parser to break
the document into chunks that the XSLT processor can handle more quickly (and
then you have to collect and reassemble the output yourself), vendor-specific
extension functions such as saxon:preview (but only in limited situations),
and using SAX-based transformation approaches such as STX. See also
http://www.biglist.com/lists/xsl-list/archives/200301/msg00804.html

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

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



<Prev in Thread] Current Thread [Next in Thread>