changeset 21:f05f0d0ee296

fix false positives
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 05 Apr 2017 11:24:11 +0100
parents 104ef815b0b0
children ca98c74a7cb1
files refs.xsl
diffstat 1 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/refs.xsl	Tue Apr 04 18:04:13 2017 +0100
+++ b/refs.xsl	Wed Apr 05 11:24:11 2017 +0100
@@ -9,8 +9,32 @@
  </xsl:template>
  
  <xsl:template match="s:c[s:f]">
-  <xsl:variable name="refs" select="analyze-string(.,$pat)/xf:match/xf:group[@nr=8]"/>
-  <xsl:if test="$refs"><e:ref c="{@r}" r="{for $ref in $refs return translate($ref,'$','')}"/></xsl:if>
+  <xsl:variable name="tokens" select="analyze-string(.,$pat)/xf:match/xf:group"/>
+  <xsl:if test="@r='B1'"><xsl:message><xsl:value-of select="$tokens/@nr"/></xsl:message>
+<xsl:message><xsl:value-of select="$tokens/."/></xsl:message>
+  </xsl:if>
+  <xsl:if test="$tokens[@nr=8]">
+   <xsl:variable name="n" select="count($tokens)"/>
+   <xsl:variable name="singles" select="for $i in (1 to $n)
+       return if ($tokens[$i][@nr=8] and not($tokens[$i - 1][@nr=10 and .=(':','!')]) and not($tokens[$i + 1][@nr=10 and .=':']))
+            then translate($tokens[$i],'$','')
+            else ()"/>
+   <xsl:variable name="ranges" select="for $i in (1 to count($tokens))
+          return if ($tokens[$i][@nr=10 and .=':' and
+                                not($i gt 2 and
+                                    $tokens[$i - 2][@nr=10 and .='!'])])
+            then translate(concat($tokens[$i - 1],':',$tokens[$i + 1]),'$','')
+            else ()"/>
+   <xsl:variable name="externals" select="for $i in (1 to count($tokens))
+          return if ($tokens[$i][@nr=7])
+            then 
+              let $bit := concat($tokens[$i],'!',
+                                 translate($tokens[$i + 2],'$',''))
+              return if ((($i+3) le $n) and $tokens[$i + 3][@nr=10 and .=':'])
+                then concat($bit,':',translate($tokens[$i + 4],'$',''))
+                else $bit
+            else ()"/>
+   <e:ref c="{@r}" r="{$singles}" rr="{$ranges}" er="{$externals}"/></xsl:if>
  </xsl:template>
  
  <xsl:template match="s:c"/>