When time has come to process big xml log files we've decided to implement streamable tree in saxon the very same way it was implemented in .net eight years ago (see How would we approach to streaming facility in xslt).
It's interesting enough that the implementation is similar to one of composable tree. There a node never stores a reference to a parent, while in the streamed tree no references to children are stored. This way only a limited subview of tree is available at any time. Implementation does not support preceding and preceding-sibling axes. Also, one cannot navigate to a node that is out of scope.
Implementation is external (there are no changes to saxon itself). To use it one needs to create an instance of DocumentInfo, which pulls data from XMLStreamReader, and to pass it as an input to a transformation:
DocumentInfo
XMLStreamReader
Controller controller = (Controller)transformer; XMLInputFactory factory = XMLInputFactory.newInstance(); StreamSource inputSource = new StreamSource(new File(input)); XMLStreamReader reader = factory.createXMLStreamReader(inputSource); StaxBridge bridge = new StaxBridge(); bridge.setPipelineConfiguration( controller.makePipelineConfiguration()); bridge.setXMLStreamReader(reader); inputSource = new DocumentImpl(bridge); transformer.transform(inputSource, new StreamResult(output));
This helped us to format an xml log file of arbitrary size. An xslt like this can do the work:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xs"> <xsl:template match="/log"> <html> <head> <title>Log</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="message"> ... </xsl:template> <xsl:template match="message[@error]"> ... </xsl:template> ... </xsl:stylesheet>
Implementation can be found at: streamedtree.zip
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u