<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">

 <xsl:output encoding='utf-8' indent='yes' doctype-system='xliff.dtd'/>
 <xsl:param name='Target'>PL</xsl:param>

 <xsl:template match="/Translations">

  <xliff version='1.0' xml:lang="en">
   <xsl:element name='file'>
    <xsl:attribute name='original'>db-output</xsl:attribute>
    <xsl:attribute name='datatype'>database</xsl:attribute>
    <xsl:attribute name='source-language'>EN</xsl:attribute>
    <xsl:attribute name='target-language'><xsl:value-of select="$Target"/></xsl:attribute>

    <header>
     <phase-group>
      <phase phase-name='prep1' process-name='preparation'></phase>
     </phase-group>
    </header>

    <body>
     <xsl:for-each select="Descriptions[@Lang='EN' and @Status!='ok']">

      <xsl:variable name='UnitID'>
       <xsl:value-of select="@PackageID"/>
      </xsl:variable>

      <!-- translation unit for Title  -->
      <xsl:element name='trans-unit'>
       <xsl:variable name='SugTitle'>
        <xsl:value-of select="/Translations/Descriptions[@PackageID=$UnitID and @Lang=$Target]/Title"/>
       </xsl:variable>

       <xsl:attribute name='id'><xsl:value-of select="$UnitID"/>-t</xsl:attribute>
       <xsl:attribute name='restype'>title</xsl:attribute>
       <xsl:element name='source'>
        <xsl:attribute name='xml:lang'><xsl:value-of select="@Lang"/></xsl:attribute>
        <xsl:value-of select="Title"/>
       </xsl:element>
       <xsl:element name='target'>
        <xsl:attribute name='xml:lang'><xsl:value-of select="$Target"/></xsl:attribute>
        <xsl:attribute name='state'><xsl:value-of select="@Status"/></xsl:attribute>
        <xsl:if test="$SugTitle!=''">
         <xsl:value-of select="$SugTitle"/>
        </xsl:if>
        <xsl:if test="$SugTitle=''">
         <xsl:value-of select="Title"/>
        </xsl:if>
       </xsl:element>
       <xsl:if test="$SugTitle!=''">
        <alt-trans>
         <xsl:element name='target'>
          <xsl:attribute name='xml:lang'><xsl:value-of select="$Target"/></xsl:attribute>
          <xsl:attribute name='phase-name'>prep1</xsl:attribute>
          <xsl:value-of select="$SugTitle"/>
         </xsl:element>
        </alt-trans>
       </xsl:if>
      </xsl:element>

      <!-- translation unit for Summary  -->
      <xsl:element name='trans-unit'>
       <xsl:variable name='SugSummary'>
        <xsl:value-of select="/Translations/Descriptions[@PackageID=$UnitID and @Lang=$Target]/Summary"/>
       </xsl:variable>

       <xsl:attribute name='id'><xsl:value-of select="$UnitID"/>-s</xsl:attribute>
       <xsl:attribute name='restype'>summary</xsl:attribute>
       <xsl:element name='source'>
        <xsl:attribute name='xml:lang'><xsl:value-of select="@Lang"/></xsl:attribute>
        <xsl:value-of select="Summary"/>
       </xsl:element>
       <xsl:element name='target'>
        <xsl:attribute name='xml:lang'><xsl:value-of select="$Target"/></xsl:attribute>
        <xsl:attribute name='state'><xsl:value-of select="@Status"/></xsl:attribute>
        <xsl:if test="$SugSummary!=''">
         <xsl:value-of select="$SugSummary"/>
        </xsl:if>
        <xsl:if test="$SugSummary=''">
         <xsl:value-of select="Summary"/>
        </xsl:if>
       </xsl:element>
       <xsl:if test="$SugSummary!=''">
        <alt-trans>
         <xsl:element name='target'>
          <xsl:attribute name='xml:lang'><xsl:value-of select="$Target"/></xsl:attribute>
          <xsl:attribute name='phase-name'>prep1</xsl:attribute>
          <xsl:value-of select="$SugSummary"/>
         </xsl:element>
        </alt-trans>
       </xsl:if>
      </xsl:element>

     </xsl:for-each>
    </body>

   </xsl:element>
  </xliff>

 </xsl:template>

</xsl:stylesheet>

