def release(self): Util.FreeDocumentIndex(self.node) for doc in self.documents.values(): Util.FreeDocumentIndex(doc) ReleaseNode(doc) try: for rtf in self.rtfs: ReleaseNode(rtf) except: import traceback traceback.print_exc() pass self.documents = None self.rtfs = None return
def execute(self, node, ignorePis=0, topLevelParams=None, writer=None, baseUri='', outputStream=None): """ Run the stylesheet processor against the given XML DOM node with the stylesheets that have been registered. Does not mutate the DOM If writer is None, use the XmlWriter, otherwise, use the supplied writer """ #FIXME: What about ws stripping? topLevelParams = topLevelParams or {} if len(self._stylesheets) == 0: raise XsltException(Error.NO_STYLESHEET) self._outputParams = self._stylesheets[0].outputParams if writer: self.writers = [writer] else: self.addHandler(self._outputParams, outputStream, 0) self._namedTemplates = {} tlp = topLevelParams.copy() for sty in self._stylesheets: sty.processImports(node, self, tlp) named = sty.getNamedTemplates() for name,template_info in named.items(): if not self._namedTemplates.has_key(name): self._namedTemplates[name] = template_info for sty in self._stylesheets: tlp = sty.prime(node, self, tlp) #Run the document through the style sheets self.writers[-1].startDocument() context = XsltContext.XsltContext(node, 1, 1, None, processor=self) try: self.applyTemplates(context, None) self.writers[-1].endDocument() Util.FreeDocumentIndex(node) result = self.writers[-1].getResult() finally: self._reset() context.release() return result