<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:tek="http://www.tektronix.com/TC"
                xmlns:cals="http://www.tektronix.com"
                xmlns:xlf="urn:oasis:names:tc:xliff:document:1.2"
                exclude-result-prefixes="cals xlf"
                version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:strip-space elements="*"/>

<xsl:variable name="tlang-little">
 <xsl:value-of select="concat(translate(//file/@target-language,
                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                       'abcdefghijklmnopqrstuvwxyz'),
                              translate(//xlf:file/@target-language,
                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                       'abcdefghijklmnopqrstuvwxyz'))" />
</xsl:variable>

<xsl:template match="xliff | body | group | trans-unit |
                     xlf:xliff | xlf:body |  
                     xlf:group | xlf:trans-unit">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="file | xlf:file">
 <xsl:variable name="tlang">
  <xsl:value-of select="@target-language" />
 </xsl:variable>
    <html xid="{concat(//*[contains(@from,'xid')],'-',//file/@target-language,//xlf:file/@target-language)}">
        <xsl:apply-templates/>
    </html>
</xsl:template>

<xsl:template match="header | xlf:header | bin-unit | xlf:bin-unit" />

<xsl:template match="group[@resname] | xlf:group[@resname]" priority="5">
 <xsl:element name="{@resname}">
   <xsl:for-each select="@*[not(local-name()='resname')]
                           [not(local-name()='objxid')]
                           [not(local-name()='id')]">
    <xsl:attribute name="{local-name()}">
     <xsl:value-of select="." />
    </xsl:attribute>
   </xsl:for-each>
  <xsl:apply-templates  />
 </xsl:element>
</xsl:template>

<xsl:template match="source | xlf:source" />

<xsl:template match="target | xlf:target">
 <xsl:element name="{parent::*/@resname}">
   <xsl:for-each select="@tek:*">
    <xsl:attribute name="{local-name()}">
     <xsl:value-of select="." />
    </xsl:attribute>
   </xsl:for-each>
  <xsl:apply-templates  />
 </xsl:element>
</xsl:template>


<xsl:template match="g | xlf:g">
 <xsl:choose>
  <xsl:when test="@ctype='x-html-a'">
   <a>
    <xsl:for-each select="@tek:*">
     <xsl:attribute name="{local-name()}">
      <xsl:value-of select="." />
     </xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates />
   </a>
  </xsl:when>
  <xsl:otherwise>
   <xsl:element name="{substring-after(@ctype,'x-html-')}">
    <xsl:apply-templates />
   </xsl:element>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

</xsl:stylesheet>

