<p>Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What's your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved?</p>
<p>Example XML input:</p>
<pre class="lang-html prettyprint-override"><code>&lt;root&gt;
    &lt;myel name=&quot;Foo&quot; /&gt;
    &lt;myel name=&quot;Bar&quot; /&gt;
&lt;/root&gt;
</code></pre>
<p>My desired CSV output:</p>
<pre><code>Foo,
Bar,
</code></pre>

Use a command-line XSLT processor such as
xsltproc
,
saxon
or
xalan
to parse the XML and generate CSV. Here's
an example
, which for your case is the stylesheet:
```
```
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

    <xsl:template match="root">
        <xsl:apply-templates select="myel"/>
    </xsl:template>

    <xsl:template match="myel">
        <xsl:for-each select="@*">
            <xsl:value-of select="."/>
            <xsl:value-of select="','"/>
        </xsl:for-each>
        <xsl:text>&#10;</xsl:text>
    </xsl:template> 
</xsl:stylesheet>
```
```