# HG changeset patch
# User Henning Brinkmann <hbrinkm@openoffice.org>
# Date 1284562193 -7200
# Node ID c8b7b7965f72202d98ad69f2830d65d22a53f74c
# Parent  27e35acbe7bcb36ff28482affc757c8218a0e957
rtftok01: spectobnf: work on output of wordmlsimplify.xsl and added handling for chrfmt

diff --git a/writerfilter/source/rtftok/makemodel.sh b/writerfilter/source/rtftok/makemodel.sh
--- a/writerfilter/source/rtftok/makemodel.sh
+++ b/writerfilter/source/rtftok/makemodel.sh
@@ -7,4 +7,4 @@
 BNFSIMPLIFY=bnfsimplify.xsl
 
 xsltproc $WORDMLSIMPLIFY $1 | xsltproc $COMMANDSEXTRACT - > $TOKENTOELEMENT &&
-xsltproc $SPECTOBNF $1 | xsltproc $BNFSIMPLIFY - | xmllint --format -
+xsltproc $WORDMLSIMPLIFY $1 | xsltproc $SPECTOBNF - | xsltproc $BNFSIMPLIFY - | xmllint --format -
diff --git a/writerfilter/source/rtftok/spectobnf.xsl b/writerfilter/source/rtftok/spectobnf.xsl
--- a/writerfilter/source/rtftok/spectobnf.xsl
+++ b/writerfilter/source/rtftok/spectobnf.xsl
@@ -495,246 +495,117 @@
   </xsl:choose>
 </xsl:template>
 
-<!--
-<xsl:template name="parseright">
-  <xsl:param name="right"/>
-  <xsl:param name="prev"/>
-  <xsl:param name="any"/>
-  <xsl:choose>
-    <xsl:when test="starts-with($right, 'N')">
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, 'N')"/>
-        <xsl:with-param name="prev">
-          <group>
-            <xsl:copy-of select="$prev"/>
-            <ref name="number"/>
-          </group>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '#PCDATA')">
-      <xsl:copy-of select="$prev"/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, '#PCDATA')"/>
-        <xsl:with-param name="prev">
-          <pcdata/>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '#SDATA')">
-      <xsl:copy-of select="$prev"/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, '#SDATA')"/>
-        <xsl:with-param name="prev">
-          <sdata/>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '#BDATA')">
-      <xsl:copy-of select="$prev"/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, '#BDATA')"/>
-        <xsl:with-param name="prev">
-          <bdata/>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, ' ')">
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, ' ')"/>
-        <xsl:with-param name="prev" select="$prev"/>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '?')">
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, '?')"/>
-        <xsl:with-param name="prev">
-          <optional>
-            <xsl:copy-of select="$prev"/>
-          </optional>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '*')">
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, '*')"/>
-        <xsl:with-param name="prev">
-          <zero-or-more>
-            <xsl:copy-of select="$prev"/>
-          </zero-or-more>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '+')">
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="substring-after($right, '+')"/>
-        <xsl:with-param name="prev">
-          <one-or-more>
-            <xsl:copy-of select="$prev"/>
-          </one-or-more>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '(')">
-      <xsl:copy-of select="$prev"/>
+<xsl:key name="paragraphs" match="/w:document/w:body/w:p" use="text()"/>
 
-      <xsl:variable name="innerandrest" select="substring-after($right, '(')"/>
-      <xsl:variable name="inner">
-        <xsl:call-template name="braceinner">
-          <xsl:with-param name="string" select="substring-after($right, '(')"/>
-          <xsl:with-param name="depth" select="1"/>
-        </xsl:call-template>
-      </xsl:variable> 
-      <xsl:variable name="innerandparen">
-        <xsl:value-of select="$inner"/>
-        <xsl:text>)</xsl:text>
-      </xsl:variable>
-      <xsl:variable name="rest" select="substring-after($innerandrest, $innerandparen)"/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="$rest"/>
-        <xsl:with-param name="prev">
-          <paren>
-          <xsl:call-template name="parseright">
-            <xsl:with-param name="right">
-              <xsl:value-of select="$inner"/>
+<xsl:template name="handlebnf">
+  <xsl:for-each select=".//w:tbl">
+    <xsl:for-each select=".//w:tr[count(.//w:tc) = 2]">
+      <xsl:variable name="definename">
+        <xsl:for-each select=".//w:tc[1]">
+          <xsl:call-template name="definename">
+            <xsl:with-param name="token">
+              <xsl:for-each select=".//w:p">
+                <xsl:value-of select="."/>
+              </xsl:for-each>
             </xsl:with-param>
           </xsl:call-template>
-          </paren>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '|')">
-      <choice>
-        <xsl:copy-of select="$prev"/>
-        <xsl:call-template name="parseright">
-          <xsl:with-param name="right" select="substring-after($right, '|')"/>
-        </xsl:call-template>
-      </choice>
-    </xsl:when>
-    <xsl:when test='starts-with($right, "&amp;")'>
-      <any>
-        <xsl:copy-of select="$prev"/>
-        <xsl:call-template name="parseright">
-          <xsl:with-param name="right" select='substring-after($right, "&amp;")'/>
-        </xsl:call-template>
-      </any>
-    </xsl:when>
-    <xsl:when test="starts-with($right, '\')">
-      <xsl:copy-of select="$prev"/>
+        </xsl:for-each>
+      </xsl:variable>
+      <xsl:if test="string-length($definename) > 0">
+        <define>
+          <xsl:attribute name="name">
+            <xsl:value-of select="$definename"/>
+          </xsl:attribute>
+          <xsl:variable name="right">
+            <xsl:for-each select=".//w:tc[2]">
+              <xsl:for-each select=".//w:p">
+                <xsl:value-of select="."/>
+              </xsl:for-each>
+            </xsl:for-each>
+          </xsl:variable>
+          <xsl:comment>
+            <xsl:value-of select="$right"/>
+          </xsl:comment>
+          <xsl:variable name="rightdestpreproc">
+            <xsl:call-template name="preprocessdestinations">
+              <xsl:with-param name="string" select="$right"/>
+            </xsl:call-template>
+          </xsl:variable>
+          <xsl:comment>
+            <xsl:value-of select="$rightdestpreproc"/>
+          </xsl:comment>            
+          <xsl:variable name="rightpreprocessed">
+            <xsl:call-template name="parensbyprecedence">
+              <xsl:with-param name="string" select="$rightdestpreproc"/>
+            </xsl:call-template>
+          </xsl:variable>
+          <xsl:comment>
+            <xsl:value-of select="$rightpreprocessed"/>
+          </xsl:comment>            
 
-      <xsl:variable name="controlandrest" select="substring-after($right, '\')"/>
-      <xsl:variable name="control">
-        <xsl:call-template name="control">
-          <xsl:with-param name="string" select="$controlandrest"/>
-        </xsl:call-template>
-      </xsl:variable>
-      <xsl:variable name="rest" select="substring-after($controlandrest, $control)"/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="$rest"/>
-        <xsl:with-param name="prev">
-          <control>
-            <xsl:attribute name="name">
-              <xsl:value-of select="$control"/>
-            </xsl:attribute>
-          </control>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test='starts-with($right, "&apos;")'>
-      <xsl:copy-of select="$prev"/>
+          <xsl:call-template name="parseright">
+            <xsl:with-param name="right" select="$rightpreprocessed"/>
+          </xsl:call-template>
 
-      <xsl:variable name="literalandrest" select='substring-after($right, "&apos;")'/>
-      <xsl:variable name="literal" select='substring-before($literalandrest, "&apos;")'/>
-      <xsl:variable name="rest" select='substring-after($literalandrest, "&apos;")'/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="$rest"/>
-        <xsl:with-param name="prev">
-          <literal>
-            <xsl:value-of select="$literal"/>
-          </literal>
-        </xsl:with-param>
-      </xsl:call-template>
-    </xsl:when>
-    <xsl:when test='starts-with($right, "&lt;")'>
-      <xsl:copy-of select="$prev"/>
+        </define>
+      </xsl:if>
+    </xsl:for-each>
+  </xsl:for-each>
+</xsl:template>
 
-      <xsl:variable name="refandrest" select='substring-after($right, "&lt;")'/>
-      <xsl:variable name="ref" select='substring-before($refandrest, "&gt;")'/>
-      <xsl:variable name="rest" select='substring-after($refandrest, "&gt;")'/>
-      <xsl:call-template name="parseright">
-        <xsl:with-param name="right" select="$rest"/>
-        <xsl:with-param name="prev">
-          <ref>
-            <xsl:attribute name="name">
-              <xsl:value-of select="$ref"/>
-            </xsl:attribute>
-          </ref>
-        </xsl:with-param>
+<xsl:template name="removetrailing">
+  <xsl:param name="string"/>
+  <xsl:param name="tail"/>
+  <xsl:choose>
+    <xsl:when test="string-length($tail) &gt; 0 and substring($string, string-length($string) - string-length($tail) + 1) = $tail">
+      <xsl:call-template name="removetrailing">
+        <xsl:with-param name="string" select="substring($string, 1, string-length($string) - string-length($tail))"/>
+        <xsl:with-param name="tail" select="$tail"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
-      <xsl:copy-of select="$prev"/>
-      <xsl:value-of select="$right"/>
+      <xsl:value-of select="$string"/>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
--->
+
+<xsl:template name="chrfmt">
+  <define name="chrfmt">
+    <any>
+      <xsl:for-each select="key('paragraphs', 'Font (Character) Formatting Properties')">
+        <xsl:for-each select="following-sibling::w:tbl[1]">
+          <xsl:for-each select="w:tr">
+            <xsl:if test="not(w:trPr/w:tblHeader)">
+              <xsl:for-each select="w:tc[1]">
+                <xsl:for-each select="w:p">
+                  <xsl:variable name="destarred">
+                    <xsl:call-template name="removetrailing">
+                      <xsl:with-param name="string">
+                        <xsl:call-template name="removetrailing">
+                          <xsl:with-param name="string" select="text()"/>
+                          <xsl:with-param name="tail"><xsl:text> </xsl:text></xsl:with-param>
+                        </xsl:call-template>
+                      </xsl:with-param>
+                      <xsl:with-param name="tail">*</xsl:with-param>
+                    </xsl:call-template>
+                  </xsl:variable>
+                  <xsl:call-template name="tokentoelement">
+                    <xsl:with-param name="token" select="substring($destarred, 2)"/>
+                  </xsl:call-template>
+                </xsl:for-each>
+              </xsl:for-each>
+            </xsl:if>
+          </xsl:for-each>
+        </xsl:for-each>
+      </xsl:for-each>
+    </any>
+  </define>
+</xsl:template>
 
 <xsl:template match="/">
   <out>
-    <xsl:for-each select=".//w:tbl">
-      <xsl:for-each select=".//w:tr[count(.//w:tc) = 2]">
-        <xsl:variable name="definename">
-          <xsl:for-each select=".//w:tc[1]">
-            <xsl:call-template name="definename">
-              <xsl:with-param name="token">
-                <xsl:for-each select=".//w:t">
-                  <xsl:value-of select="."/>
-                </xsl:for-each>
-              </xsl:with-param>
-            </xsl:call-template>
-          </xsl:for-each>
-        </xsl:variable>
-        <xsl:if test="string-length($definename) > 0">
-          <define>
-            <xsl:attribute name="name">
-              <xsl:value-of select="$definename"/>
-            </xsl:attribute>
-            <xsl:variable name="right">
-              <xsl:for-each select=".//w:tc[2]">
-                <xsl:for-each select=".//w:t">
-                  <xsl:value-of select="."/>
-                </xsl:for-each>
-              </xsl:for-each>
-            </xsl:variable>
-            <xsl:comment>
-              <xsl:value-of select="$right"/>
-            </xsl:comment>
-            <xsl:variable name="rightdestpreproc">
-              <xsl:call-template name="preprocessdestinations">
-                <xsl:with-param name="string" select="$right"/>
-              </xsl:call-template>
-            </xsl:variable>
-            <xsl:comment>
-              <xsl:value-of select="$rightdestpreproc"/>
-            </xsl:comment>            
-            <xsl:variable name="rightpreprocessed">
-              <xsl:call-template name="parensbyprecedence">
-                <xsl:with-param name="string" select="$rightdestpreproc"/>
-              </xsl:call-template>
-            </xsl:variable>
-            <xsl:comment>
-              <xsl:value-of select="$rightpreprocessed"/>
-            </xsl:comment>            
-
-            <xsl:call-template name="parseright">
-              <xsl:with-param name="right" select="$rightpreprocessed"/>
-            </xsl:call-template>
-
-          </define>
-        </xsl:if>
-      </xsl:for-each>
-    </xsl:for-each>
+    <xsl:call-template name="handlebnf"/>
+    <xsl:call-template name="chrfmt"/>
   </out>
 </xsl:template>
 
