<?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' />
 <xsl:param name='Target'>PL</xsl:param>

 <xsl:template match="/xliff/file/body">

  <Translations>
   <u:sync xmlns:u="urn:schemas-microsoft-com:xml-updategram"
           mapping-schema="Descriptions.xdr">

    <xsl:for-each select="trans-unit[@restype='title' and @approved='yes']">

     <xsl:variable name='PackageID'><xsl:value-of select="substring-before(@id, '-')"/></xsl:variable>
     <xsl:variable name='SummaryID'><xsl:value-of select="$PackageID"/>-s</xsl:variable>
     <xsl:variable name='Title'><xsl:value-of select='target'/></xsl:variable>

     <xsl:variable name='Summary'><xsl:value-of
      select="/xliff/file/body/trans-unit[@restype='summary' and @approved='yes' and @id=$SummaryID]/target"/></xsl:variable>

     <xsl:if test="$Title=''">
      <xsl:message terminate='yes'>Empty value found for title id=<xsl:value-of select='$PackageID'/></xsl:message>
     </xsl:if>
     <xsl:if test="$Summary=''">
      <xsl:message terminate='yes'>Empty value found for summary id=<xsl:value-of select='$SummaryID'/></xsl:message>
     </xsl:if>

     <u:before>
      <xsl:element name='Descriptions'>
       <xsl:attribute name='PackageID'><xsl:value-of select="$PackageID"/></xsl:attribute>
       <xsl:attribute name='Lang'>EN</xsl:attribute>
       <xsl:attribute name='Status'><xsl:value-of select="target/@state"/></xsl:attribute>
      </xsl:element>
     </u:before>
     <u:after>
      <xsl:element name='Descriptions'>
       <xsl:attribute name='PackageID'><xsl:value-of select="$PackageID"/></xsl:attribute>
       <xsl:attribute name='Lang'>EN</xsl:attribute>
       <xsl:attribute name='Status'>ok</xsl:attribute>
      </xsl:element>
     </u:after>

     <u:before/>
     <u:after>
      <xsl:element name='Descriptions'>
       <xsl:attribute name='PackageID'><xsl:value-of select="$PackageID"/></xsl:attribute>
       <xsl:attribute name='Lang'><xsl:value-of select="$Target"/></xsl:attribute>
       <Title><xsl:value-of select="$Title"/></Title>
       <Summary><xsl:value-of select="$Summary"/></Summary>
      </xsl:element>
     </u:after>

    </xsl:for-each>

   </u:sync>
  </Translations>

 </xsl:template>

</xsl:stylesheet>

