published by whitemice on Wed, 09/09/2020 - 14:06
Using lxml's etree to iteratively parse an XML document and I wanted to drop a specific element from the stream...
for event, element in etree.iterparse(self.rfile, events=("end",)):
if (event == 'end') and (element.tag == 'row'):
self.wfile.write(etree.tostring(element))
elif (event == 'end') and (element.tag == name_of_element_to_drop):
element.getparent().remove(element) # drop element
The secret sauce is: element.getparent().remove(element)
published by whitemice on Tue, 12/02/2014 - 10:31
The xsltproc command allows the processing of an XML document with an XSLT template.
xsltproc rentalouts.xslt rentalouts.xml
Text 1: Perform the transform "rentalouts.xslt" on the document "rentalouts.xml".
A lesser known feature of xsltproc is the ability to pass parameters - these become XSLT variables - to the transformation.
published by whitemice on Fri, 07/16/2010 - 00:00
Maybe this should be obvious, but it wasn't to me. I've got an XML document and an XSLT stylesheet. But that stylesheet just produces text, not XML; it is essentially a template for an e-mail. So I was extending OIE's transformAction for performing XSLT transforms that produce other than XML... but the documentation is a bit thin and every example is XML results. The trick is pretty simple, just
unicode(result)
and make sure [of course] that you have