..

XML to TSV

Use XSLT (Extensible Stylesheet Language Transformation) to perform the transformation to the exact format you need.

The following steps can be used to convert XML files exported from WorldServer to TSV (tab-separated values). TSV is an alternative to the common comma-separated values (CSV) format, which often causes difficulties because of the need to escape commas and semicolons inside text and URLs – literal commas and semicolons are very common in text data, but literal tab stops are infrequent in running text.

XSL Style Sheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tsv="tsv:tsv">
 <xsl:output method="text" encoding="utf-8"/>

 <xsl:strip-space elements="*"/>
 <!-- Set tab as character delimiter to avoid commas and semicolons inside the text -->
 <xsl:variable name="delimiter" select="'&#009;'"/>
 <tsv:columns>
 <column>Key</column>
 <column>Value</column>
 </tsv:columns>

 <xsl:template match="Property">
 <xsl:text disable-output-escaping="yes">&#009;</xsl:text>

 <!-- Output rows for each matched property -->
 <xsl:apply-templates select="*"/>
 </xsl:template>

 <xsl:template match="Property">
 <xsl:variable name="property" select="."/>
 <!-- Loop through the columns in order -->
 <xsl:for-each select="document('')/*/tsv:columns/*">
 <!-- Extract the column name and value -->
 <xsl:variable name="column" select="."/>
 <xsl:variable name="value" select="$property/*[name() = $column]"/>
 <xsl:value-of select="$value"/>
 <!-- Add the delimiter -->
 <xsl:if test="position() != last()">
 <xsl:value-of select="$delimiter"/>
 </xsl:if>
 </xsl:for-each>
 <!-- Add a newline at the end of the record -->
<xsl:text>
</xsl:text>
 </xsl:template>
</xsl:stylesheet>

Open a Terminal window and use the command line XSLT processor:

xsltproc stylesheet.xsl Exported_XML.xml > name_of_the_converted_file.tsv



More information about xsltproc can be found here:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xsltproc.1.html
http://xmlsoft.org/XSLT/xsltproc.html