extend the indexing accumulator to be a mapping from NKJP index onto the accumulator-generated  traverse value that gets turned into the KorAP index; this way we get free lookup of a sort, at least for cases where all we need is an old->new mapping

Change-Id: I8cf9a914d348c7a691f0523d4cd8e820ab82ef43
diff --git a/nkjp2korap.xsl b/nkjp2korap.xsl
index 4aae734..05dec9d 100644
--- a/nkjp2korap.xsl
+++ b/nkjp2korap.xsl
@@ -62,8 +62,12 @@
   <xsl:mode name="header-text" on-no-match="text-only-copy"/>
   <xsl:mode use-accumulators="#all"/>
 
-  <xsl:accumulator name="element-index" as="xs:integer" initial-value="0">
-    <xsl:accumulator-rule match="tei:*[ancestor-or-self::tei:text]" select="$value + 1" phase="start"/>
+  <xsl:accumulator name="element-index" as="map(xs:string, xs:integer)" initial-value="map{'':0}">
+    <xsl:accumulator-rule match="tei:*[ancestor-or-self::tei:text]" phase="start">
+      <xsl:variable name="prev_idx" as="xs:integer"
+        select="map:get($value, map:keys($value)[last()])"/>
+      <xsl:sequence select="map { string(@xml:id): $prev_idx + 1 }"/>
+    </xsl:accumulator-rule>
   </xsl:accumulator>
   
   <xsl:accumulator name="elem-offset-seq" as="map(xs:string, item()+)+" initial-value="(map{'null':(0,0)})">
@@ -433,7 +437,8 @@
     </xsl:variable>
     
     <xsl:variable name="my_name" select="local-name()" as="xs:string"/>
-    <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/>
+    <!--<xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/>-->
+    <xsl:variable name="my_index" select="map:get(fn:accumulator-before('element-index'),string(@xml:id))" as="xs:integer"/>
     
     <xsl:element name="span" namespace="{$KorAP_namespace}">
       <xsl:attribute name="id" select="'s' || $my_index"/>
@@ -507,7 +512,8 @@
     <xsl:variable name="my_choice-id" select="substring-after($my_disamb//tei:f[@name eq 'choice']/@fVal,'#')" as="xs:string"/>
     <xsl:variable name="my_choice-lex" select="$my_morph-seg//tei:f[@name eq 'interps']/tei:fs[@type eq 'lex'][descendant::tei:symbol[@xml:id eq $my_choice-id]]" as="node()"/>
     <xsl:variable name="chosen-msd" as="xs:string" select="$my_choice-lex/descendant::tei:symbol[@xml:id eq $my_choice-id]/@value"/>
-    <xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/>
+    <!--<xsl:variable name="my_index" select="fn:accumulator-before('element-index')" as="xs:integer"/>-->
+    <xsl:variable name="my_index" select="map:get(fn:accumulator-before('element-index'),string(@xml:id))" as="xs:integer"/>
     
     <xsl:element name="span" namespace="{$KorAP_namespace}">
       <xsl:attribute name="id" select="'m' || $my_index"/>