Using memoQ to translate standard XLIFF (XML Localisation Interchange File Format) files can be made that bit more user friendly when you take advantage of the built-in feature to use XSLT transformations. Since I can’t get my head around namespaces, my simple transformation ended up strewn with unreadable references to local-name() nodes. As ever, there is an easier way.

Take a standard XLIFF file along the lines of:

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0" xmlns="urn:oasis:names:tc:xliff:document:1.2">
   <file source-language="en" datatype="plaintext" original="Project">
      <header/>
      <body>
         <trans-unit id="string">
            <source>This is the source content.</source>
         </trans-unit>
      </body>
   </file>
</xliff>

We can identify the nodes in the source using standard XPath syntax having defined the namespaces in the header:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xlf="urn:oasis:names:tc:xliff:document:1.2"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   exclude-result-prefixes="xsl xlf xsi"
>
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:text disable-output-escaping='yes'><!DOCTYPE html></xsl:text>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
   <link rel="stylesheet" type="text/css" href="yourStyles.css" />
   <title>XML Preview</title>
</head>
<body>
   <h1><xsl:value-of select="xlf:xliff/xlf:file/@original"/></h1>
   <xsl:for-each select="xlf:xliff/xlf:file/xlf:body/xlf:trans-unit">
      <div class="id"><xsl:value-of select="@id"/></div>
      <div class="content"><xsl:value-of select="xlf:source"/></div><br>   </xsl:for-each>
</body><br></html><br></xsl:template><br></xsl:stylesheet>

This produces a basic, ugly but ultimately workable HTML file which memoQ can display in its preview pane:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <link rel="stylesheet" type="text/css" href="yourStyles.css"/>
      <title>XML Preview</title>
   </head>
   <body>
      <h1>messages</h1>
      <div class="id">string</div>
      <div class="content">This is the source content.</div>
   </body>
</html>

Obviously you can add references to any other information available in your XLIFF files, and then serve and style up the resulting HTML in any desired shape or form, but this basic scaffolding might help someone out there avoid the namespace minefield I ran into!

[Image courtesy of @emilep]