>If you're doing this on a UNIX-flavored system, consider using sed.

Actually, sed does exactly the same thing -- it passes the whole file
through the tool in order to find and alter specific points within it.

Well-formed XML files have a single root element, so you really can't just
append to them. Theoretically, it might be possible to write a tool that
opens an XML file in read/write mode, seeks backward through the file to
find the last end-tag (which one certainly hopes would be the end of that
root element), saves that tag and any PIs or comments which follow it,
overwrites the file with new data (additional children of that root
element), and then reissues the end-tag and "trailer" information... but
I've never seen anyone do it, and it really isn't the sort of thing XSLT,
per se, is designed for. If you wanted to try the experiment, I'd suggest
encapsulating it in a special-purpose serializer, and extending Xalan's
handling of xsl:output so a new "method" keyword selected that
serializer... something like
     <xsl:output method="xalanXMLAppend"/>

But of course that kind of custom code is a nonportable solutoin. If you
want an approach that will also work with other XSLT processors, your best
answer may be to have the stylesheet read in the old file, passing most of
it through unaltered, and write out the new data at the appropriate point
in that process.

Or write out a new file, and use a separate postprocessing stage (maybe a
stylesheet, maybe not) to append its data to the document you're trying to
merge it with.

Reply via email to