Sunday, January 23, 2011

XSLT transformation which creates a HTML preview of a TMX file

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

<xsl:template match="/tmx/body">
<html>
    <head>
        <title>
            TMX Table
        </title>
    </head>
    <body>
        <table border="1" cellpadding="5">
            <tr>
                <td>Source</td>
                <td>Translation</td>
            </tr>
                <xsl:apply-templates/>
        </table>
    </body>
</html>
</xsl:template>

<xsl:template match="tu">
<tr>
    <xsl:apply-templates/>
</tr>
</xsl:template>


<xsl:template match="tuv">
<td>
    <xsl:apply-templates/>
</td>
</xsl:template>

<xsl:template match="seg">
<xsl:value-of select="."/>
</xsl:template>


</xsl:stylesheet>