successfully switched to ann_morpho for structure.xml, with some lingering questions asked via slack

Change-Id: Iae09ef6cb943c74498243bd1082cb4e953556522
diff --git a/nkjp2korap.xsl b/nkjp2korap.xsl
index 37248ee..2ea77af 100644
--- a/nkjp2korap.xsl
+++ b/nkjp2korap.xsl
@@ -58,6 +58,7 @@
   
 <!--           MODES               -->
 
+  <xsl:mode name="struct" on-no-match="deep-skip"/>
   <xsl:mode name="corpus-header" on-no-match="deep-skip"/>
   <xsl:mode name="text-header" on-no-match="deep-skip"/>
   <xsl:mode name="text_inside_header" on-no-match="text-only-copy"/>
@@ -158,9 +159,34 @@
         string(@xml:id): ($our_base,$preceding_index)
         }"/>
     </xsl:accumulator-rule>
+    
+    <xsl:accumulator-rule match="tei:body" phase="end">
+      <xsl:variable name="preceding_index" as="xs:integer">
+        <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
+        <xsl:sequence select="map:get($the_tail, map:keys($the_tail)[1])[2]"/>
+      </xsl:variable>
+      
+      <xsl:sequence select="
+        $value,
+        map {
+        string(@xml:id): (0, $preceding_index)
+        }"/>
+    </xsl:accumulator-rule>
+    
+    <xsl:accumulator-rule match="tei:text" phase="end">
+      <xsl:variable name="preceding_index" as="xs:integer">
+        <xsl:variable name="the_tail" as="map(*)" select="head(reverse($value))"/>
+        <xsl:sequence select="map:get($the_tail, map:keys($the_tail)[1])[2]"/>
+      </xsl:variable>
+      
+      <xsl:sequence select="
+        $value,
+        map {
+        string(@xml:id): (0, $preceding_index)
+        }"/>
+    </xsl:accumulator-rule>
+    
   </xsl:accumulator>
-  
-  
 
   <xsl:accumulator name="segmentation-offsets" as="map(xs:string, item()+)+" initial-value="(map{'null':(0,0)})">
     
@@ -425,13 +451,13 @@
       <xsl:with-param name="target" select="$targetBaseDir ||  '/data.xml'" as="xs:string"/>
     </xsl:call-template>
 
- <!--   <xsl:call-template name="create_struct">
+    <xsl:call-template name="create_struct">
       <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
-      <xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"
+      <xsl:with-param name="ann_morphosyntax.doc" select="$ann_morphosyntax.doc"
         as="document-node()"/>
       <xsl:with-param name="target" select="$targetBaseDir ||  '/struct/structure.xml'" as="xs:string"
       />
-    </xsl:call-template>-->
+    </xsl:call-template>
     
 <!--    <xsl:call-template name="create_morpho">
       <xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
@@ -535,7 +561,7 @@
 
   <xsl:template name="create_struct">
     <xsl:param name="compoundID" as="xs:string"/>
-    <xsl:param name="ann_segmentation.xml" as="document-node()"/>
+    <xsl:param name="ann_morphosyntax.doc" as="document-node()"/>
     <xsl:param name="target" as="xs:string"/>
     
     <xsl:result-document encoding="UTF-8" method="xml" indent="yes"
@@ -546,15 +572,15 @@
         <xsl:attribute name="version" select="$KorAP-XML_version"/>
 
         <xsl:element name="spanList" namespace="{$KorAP_namespace}">
-          <xsl:apply-templates select="$ann_segmentation.xml//tei:text" mode="struct"/>          
+          <xsl:apply-templates select="$ann_morphosyntax.doc/tei:teiCorpus/tei:TEI/tei:text" mode="struct"/>          
         </xsl:element>
       </xsl:element>
     </xsl:result-document>
   </xsl:template>
   
-  <xsl:template match="tei:*" mode="struct">
+  <xsl:template match="tei:text | tei:body | tei:p | tei:s | tei:seg[tei:fs/tei:f[@name eq 'disamb']]" mode="struct">
     <xsl:variable name="offsets" as="xs:integer+">
-      <xsl:sequence select="map:get(fn:accumulator-after('segmentation-offsets')[last()], string(@xml:id))"/>
+      <xsl:sequence select="map:get(fn:accumulator-after('morpho-offsets')[last()], string(@xml:id))"/>
     </xsl:variable>
     
     <xsl:variable name="my_name" select="local-name()" as="xs:string"/>