Today I felt the Uroboros snake breathing just in my cubicle when I realized XSLT is able to write output to the input tree. Funny, huh?
XmlDocument doc = new XmlDocument(); doc.Load("input.xml"); XslTransform xslt = new XslTransform(); xslt.Load("test.xsl"); XmlNodeWriter nw = new XmlNodeWriter(doc.DocumentElement, false); xslt.Transform(doc, null, nw); nw.Close();This transformation outputs result tree directly to the document element of the input tree! Moreover, during the transformation process the input tree is being dynamically changed and XSLT processor even is able to see the output tree in input and to process it again!
Of course you'd better then not to cycle transformation forever using plain <xsl:copy-of select="/"/>.
Practical usage? Highly-efficient update of in-memory DOM using XSLT with no any interim buffers. Kinda dangerous though, because output can destroy input prior it's processed or to loop forever, but nice one anyway.
Leave a comment