<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               version="1.0">

<xsl:output method="xml" indent="yes" encoding="utf-8" />

<xsl:strip-space elements="*" />


<xsl:template match="node()|@*">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="/">
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2"
 xmlns:tek="http://www.tektronix.com/TC"
 xmlns:cals="http://www.tektronix.com"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-strict.xsd"
 version="1.2" xml:lang="en-us">
  <file source-language="EN" 
        datatype="plaintext" 
        target-language="{document('tlang.xml')/lang}"
        original="html">
  <header>
   <xsl:for-each select="//html/@*">
    <note from="{local-name()}">
     <xsl:value-of select="." />
    </note>
   </xsl:for-each>
  </header>
  <body>
     <xsl:apply-templates />
  </body>
  </file>
 </xliff>
</xsl:template>

<!-- inlines -->
<xsl:template match="b | i | sup | sub">
  <g id="{generate-id()}" ctype="{concat('x-html-',local-name())}" 
       xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <xsl:apply-templates/>
  </g>
</xsl:template>

<!-- mixed content elements -->

<xsl:template match="p | li | h1 | h2" >
 <xsl:variable name="ElName" select="local-name()" />
 <trans-unit resname="{$ElName}" xmlns="urn:oasis:names:tc:xliff:document:1.2" 
                                 xmlns:tek="http://www.tektronix.com/TC"
                                 id="{generate-id()}">
  <xsl:for-each select="@*">
   <xsl:attribute name="{concat('tek:',local-name())}">
    <xsl:value-of select="." />
   </xsl:attribute>
  </xsl:for-each>
  <source xml:lang="EN">
   <xsl:apply-templates />
  </source>
  <target state="needs-translation" 
          xml:lang="{document('tlang.xml')/lang}">
   <xsl:apply-templates />
  </target>
  </trans-unit>
</xsl:template>

 <xsl:template match="a">
  <g id="{generate-id()}" ctype="{concat('x-html-',local-name())}"
     xmlns="urn:oasis:names:tc:xliff:document:1.2"
     xmlns:tek="http://www.tektronix.com/TC">
     <xsl:for-each select="@*">
      <xsl:attribute name="{concat('tek:',local-name())}">
       <xsl:value-of select="." />
      </xsl:attribute>
     </xsl:for-each>
    <xsl:apply-templates />
  </g>
</xsl:template>

<!-- wrapper elements -->

<xsl:template match="table | tr | ul | th | td">
 <xsl:variable name="wrapper-element" select="local-name()" />
    <group resname="{$wrapper-element}" xmlns="urn:oasis:names:tc:xliff:document:1.2" 
                                 xmlns:tek="http://www.tektronix.com/TC">
     <xsl:for-each select="@*">
      <xsl:attribute name="{concat('tek:',local-name())}">
       <xsl:value-of select="." />
      </xsl:attribute>
     </xsl:for-each>
     <xsl:attribute name="id">
      <xsl:value-of select="concat('d-',$wrapper-element,generate-id())" />
     </xsl:attribute>
     <xsl:apply-templates />
     <bin-unit id="{concat(generate-id(),local-name())}" 
               mime-type="text/internal-Tek">
      <bin-source>
       <external-file href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "/>
      </bin-source>
     </bin-unit>
    </group>
</xsl:template>

<xsl:template match="html">
 <xsl:apply-templates />
</xsl:template>

</xsl:transform>

