Python etree XSLT Requires Tag output?
<p>I'm trying to make a simple XML --> CSV script, using XSLT. I found that etree seems to "want" a tag to output... Does anyone know a workaround? Yes, I've seen this post: <a href="https://stackoverflow.com/questions/365312/xml-to-csv-using-xslt">XML to CSV Using XSLT</a>.</p>

<p>See below...</p>

<p>Here's a sample XML data just for reference. My code doesn't even do anything with the data yet, as it was failing to even write a header. </p>

<pre><code>    &lt;projects&gt;
    &lt;project&gt;
    &lt;name&gt;Shockwave&lt;/name&gt; 
    &lt;language&gt;Ruby&lt;/language&gt; 
    &lt;owner&gt;Brian May&lt;/owner&gt; 
    &lt;state&gt;New&lt;/state&gt; 
    &lt;startDate&gt;31/10/2008 0:00:00&lt;/startDate&gt; 
    &lt;/project&gt;
    &lt;project&gt;
    &lt;name&gt;Other&lt;/name&gt; 
    &lt;language&gt;Erlang&lt;/language&gt; 
    &lt;owner&gt;Takashi Miike&lt;/owner&gt; 
    &lt;state&gt; Canceled &lt;/state&gt; 
    &lt;startDate&gt;07/11/2008 0:00:00&lt;/startDate&gt; 
    &lt;/project&gt;
    &lt;/projects&gt;
</code></pre>

<p>Here's my script:</p>

<pre><code>    import sys
    from lxml import etree

    system_file = sys.argv[1]
    xml_file = sys.argv[2]

    sys_txt = open( system_file,"r" ).read()
    xsl_txt = open( "csv_file.xslt","r" ).read()


    sysroot = etree.fromstring( sys_txt )
    xslroot = etree.fromstring( xsl_txt )
    transform = etree.XSLT( xslroot )

    with open( xml_file, "w" ) as f:
        f.write(etree.tostring( transform(sysroot) ) )
</code></pre>

<p>This XSLT code does NOT work ( etree.tostring... = None ):</p>

<pre><code>    &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="text"/&gt;
    &lt;xsl:template match="/"&gt;
    Hi
    &lt;/xsl:template&gt;

    &lt;/xsl:stylesheet&gt;
</code></pre>

<p>But THIS XSLT does work... seems etree needs to output an XML file?</p>

<pre><code>    &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="text"/&gt;
    &lt;xsl:template match="/"&gt;
    &lt;dummy&gt;
    Hi
    &lt;/dummy&gt;
    &lt;/xsl:template&gt;

    &lt;/xsl:stylesheet&gt;
</code></pre>

<p>At this point I'm thinking I can proceed with a dummy tag, then remove it at end... </p>