<?xml version="1.0" encoding="UTF-8"?>
<!-- We must define several namespaces, because we need them to access -->
<!-- the document model of the in-memory OpenOffice.org document.      -->
<!-- If we want to access more parts of the document model, we must    -->
<!-- add there namesspaces here, too.                                  -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
       xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
       xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
       exclude-result-prefixes="office table text">

<xsl:output method = "xml" indent = "yes" encoding = "UTF-8" omit-xml-declaration = "no"/>


<!-- Process the document model -->
<xsl:template match="/">
  <emkisMetsayhistuLiikmedImport version="v1">
    <docOigused>1</docOigused>
    <docVorm>emkisMetsayhistuLiikmedImport</docVorm>
    <tbl_metsayhistuLiikmed oigused="5">
      <!-- Process all tables -->
      <xsl:apply-templates select="//table:table"/>
    </tbl_metsayhistuLiikmed>
  </emkisMetsayhistuLiikmedImport>
</xsl:template>

<xsl:template match="table:table">
  <!-- Process all table-rows after the column labels in table-row 1 -->
  <xsl:for-each select="table:table-row">
   <xsl:if test="position()>1">
    <rida_emkisMetsayhistuLiige oigused="3">
     <!-- Process the first for columns -->
     <xsl:for-each select="table:table-cell">
      <xsl:choose>
       <xsl:when test="position()=1">
       <eesnimi oigused="1"><xsl:value-of select="text:p"/></eesnimi>
       </xsl:when>
       <xsl:when test="position()=2">
       <nimi oigused="1"><xsl:value-of select="text:p"/></nimi>
      </xsl:when>
       <xsl:when test="position()=3">
       <isikukood oigused="1"><xsl:value-of select="text:p"/></isikukood>
      </xsl:when>
       <xsl:when test="position()=4">
       <liik oigused="1"><xsl:value-of select="text:p"/></liik>
      </xsl:when>
      </xsl:choose>
     </xsl:for-each>
    </rida_emkisMetsayhistuLiige>
   </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
