Author: ks
Date: Sat Nov 17 21:10:47 2007
New Revision: 6754

Log:
- Implemented paragraphs' breaking by block tags.

Modified:
    experimental/Document/src/converters/ezp3_ezp4.xsl
    experimental/Document/tests/files/ezp3_sample.xml

Modified: experimental/Document/src/converters/ezp3_ezp4.xsl
==============================================================================
--- experimental/Document/src/converters/ezp3_ezp4.xsl [iso-8859-1] (original)
+++ experimental/Document/src/converters/ezp3_ezp4.xsl [iso-8859-1] Sat Nov 17 
21:10:47 2007
@@ -14,28 +14,67 @@
  <xsl:choose>  
   <xsl:when test="$level = 0">
    <document>
-    <xsl:apply-templates select="paragraph"/>
+    <xsl:apply-templates />
    </document>
   </xsl:when>
   <xsl:otherwise>
-   <xsl:apply-templates select="paragraph"/>
+   <xsl:apply-templates />
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="paragraph">
+   <xsl:apply-templates mode='common'/>
+</xsl:template>
+
+<!-- A common template for inline tags -->
+<xsl:template match="strong|emphasize|text()" mode="common">
+ <xsl:choose>
+   <!-- If a parent is paragraph -->
+   <xsl:when test="boolean(parent::paragraph)">
+    <!-- We call render_para template only for the first inline tag,
+         all the following inline tags are rendered inside that template. -->
+    <xsl:if test="boolean(count(preceding-sibling::node()))">
+     <xsl:variable name="prevname" select="name(preceding-sibling::node()[1])" 
/>
+     <!-- Check that the previous tag is not inline
+          TODO: add all block tags -->
+     <xsl:if test="($prevname = 'embed') or ($prevname = 'table')">
+      <xsl:call-template name='render_para' />
+     </xsl:if>
+    </xsl:if>
+    <!-- Check that there is no previous element (current is the first child) 
-->
+    <xsl:if test="(count(preceding-sibling::node()) = 0)">
+     <xsl:call-template name='render_para' />
+    </xsl:if>
+   </xsl:when>
+   <xsl:otherwise>
+    <xsl:apply-templates mode='special' select='.'/>
+   </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="render_para">
  <para>
-  <xsl:apply-templates/>
+  <xsl:apply-templates mode="special" select="."/>
+  <xsl:apply-templates mode="special" 
select="set:leading(following-sibling::node(),following-sibling::*[name() = 
'embed' or name() = 'table'])"/>
  </para>
 </xsl:template>
 
-<xsl:template match="strong|emphasize">
+<!-- TODO: add all block tags -->
+<xsl:template match="embed|table" mode='common'>
+ <xsl:copy>
+  <xsl:apply-templates/>
+ </xsl:copy>
+</xsl:template>
+
+<!-- Specific templates for inline tags -->
+<xsl:template match="strong|emphasize" mode="special">
  <xsl:copy>
   <xsl:apply-templates/>
  </xsl:copy>
 </xsl:template>
               
-<xsl:template match="text()">
+<xsl:template match="text()" mode="special">
  <xsl:copy-of select="."/>
 </xsl:template>
 

Modified: experimental/Document/tests/files/ezp3_sample.xml
==============================================================================
--- experimental/Document/tests/files/ezp3_sample.xml [iso-8859-1] (original)
+++ experimental/Document/tests/files/ezp3_sample.xml [iso-8859-1] Sat Nov 17 
21:10:47 2007
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <section>
     <paragraph>abc
-        <strong>def</strong></paragraph>
+        <strong>def</strong><embed />ghi<strong>jkl</strong></paragraph>
 </section>
 


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to