Eliminated spurious whitespace (which probably didn't hurt, but...)
Change-Id: I51b77997e9e1dec75ae92dbc66c1c9e1f439ccd1
diff --git a/nkjp2korap.xsl b/nkjp2korap.xsl
index 07e7d1f..1449770 100644
--- a/nkjp2korap.xsl
+++ b/nkjp2korap.xsl
@@ -89,7 +89,7 @@
<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:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + + xs:integer(f:is_preceded_by_ws(.,true()))"/>
+ <xsl:variable name="our_base" as="xs:integer" select="if($preceding_index eq 0) then $preceding_index else $preceding_index + xs:integer(f:is_preceded_by_ws(.,true()))"/>
<xsl:sequence select="
$value,
@@ -185,41 +185,54 @@
<xsl:sequence select="$rel_depth"/>
</xsl:function>
-<xsl:function name="f:is_preceded_by_ws" as="xs:boolean">
+ <xsl:function name="f:is_preceded_by_ws" as="xs:boolean">
<xsl:param name="node" as="element()"/>
<xsl:param name="suppress_initial" as="xs:boolean"/>
- <xsl:choose>
- <xsl:when test="local-name($node) eq 'seg'">
- <xsl:choose>
- <xsl:when test="$node/@nkjp:nps"><xsl:sequence select="fn:false()"/></xsl:when>
- <xsl:when test="$node/preceding::tei:seg[count(@nkjp:rejected) eq 0][ancestor::tei:s[descendant::tei:seg = $node]]"><xsl:sequence select="fn:true()"/></xsl:when>
- <!-- this is checking if we're preceding by a seg under the same tei:s, modulo choice/paren -->
- <!-- THIS CHECK should be streamlined for efficiency, maybe try comparing positions in the descendant axis -->
- <xsl:otherwise>
- <xsl:sequence
- select="not($suppress_initial) and not($node[count(preceding-sibling::tei:seg) eq 0]/ancestor::tei:s[count(preceding-sibling::tei:s) eq 0]/ancestor::tei:p[count(preceding-sibling::tei:p) eq 0])"
- />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="local-name($node) eq 's'">
- <xsl:choose>
- <xsl:when test="exists($node/preceding-sibling::tei:s)"><xsl:sequence select="fn:true()"/></xsl:when>
- <xsl:otherwise>
- <xsl:sequence select="not($suppress_initial) and exists($node/ancestor::tei:p[1]/preceding-sibling::tei:p)"/>
- </xsl:otherwise>
- </xsl:choose>
-
- </xsl:when>
- <xsl:when test="local-name($node) eq 'p'">
- <xsl:sequence select="exists($node/preceding-sibling::tei:p)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="yes" select="'Wrong argument passed to f:is_preceded_by_ws(): ' || local-name($node) || ' Only p, s, seg are allowed.'"></xsl:message>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:function>
+ <xsl:choose>
+ <xsl:when test="local-name($node) eq 'seg'">
+ <xsl:choose>
+ <xsl:when test="$node/@nkjp:nps">
+ <xsl:sequence select="fn:false()"/>
+ </xsl:when>
+ <xsl:when
+ test="$node/ancestor::tei:s[count(preceding-sibling::tei:s) eq 0] and $node/ancestor::tei:p[count(preceding-sibling::tei:p) eq 0] and not($node/preceding::tei:seg[count(@nkjp:rejected) eq 0])">
+ <xsl:sequence select="fn:false()"/>
+ <!-- the otherwise very costly check for preceding segs fires only if the first two are true, so it will have minimal search space -->
+ </xsl:when>
+ <xsl:when
+ test="$suppress_initial and $node/ancestor::tei:s/descendant::tei:seg[count(@nkjp:rejected) eq 0][1]/@xml:id eq $node/@xml:id">
+ <!-- I forget how node identity works now, so let me just compare the IDs -->
+ <xsl:sequence select="fn:false()"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:sequence select="fn:true()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:when test="local-name($node) eq 's'">
+ <xsl:choose>
+ <xsl:when test="exists($node/preceding-sibling::tei:s)">
+ <xsl:sequence select="fn:true()"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:sequence
+ select="not($suppress_initial) and exists($node/ancestor::tei:p[1]/preceding-sibling::tei:p)"
+ />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:when>
+ <xsl:when test="local-name($node) eq 'p'">
+ <xsl:sequence select="exists($node/preceding-sibling::tei:p)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="yes"
+ select="'Wrong argument passed to f:is_preceded_by_ws(): ' || local-name($node) || ' Only p, s, seg are allowed.'"
+ />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:function>
<!-- UTILITY TEMPLATES -->
@@ -300,7 +313,7 @@
<xsl:with-param name="target" select="$targetBaseDir || '/struct/structure.xml'" as="xs:string"
/>
</xsl:call-template>
-
+
<xsl:call-template name="create_morpho">
<xsl:with-param name="compoundID" select="$compoundID" as="xs:string"/>
<xsl:with-param name="ann_segmentation.xml" select="$ann_segmentation.xml"