[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML to XML transformation

Subject: Re: XML to XML transformation
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 14 Apr 2003 13:29:08 -0600 (MDT)
cocoon xml to xml
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.