Author: ks Date: Sun Nov 18 19:01:51 2007 New Revision: 6755 Log: - Added support for headers, linebreaks, links, attributes in ezp3->ezp4 converter.
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] Sun Nov 18 19:01:51 2007 @@ -14,21 +14,32 @@ <xsl:choose> <xsl:when test="$level = 0"> <document> - <xsl:apply-templates /> + <xsl:apply-templates> + <xsl:with-param name="level" select="$level + 1"/> + </xsl:apply-templates> </document> </xsl:when> <xsl:otherwise> - <xsl:apply-templates /> + <xsl:apply-templates> + <xsl:with-param name="level" select="$level + 1"/> + </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="paragraph"> - <xsl:apply-templates mode='common'/> + <xsl:apply-templates mode="common"/> +</xsl:template> + +<xsl:template match="header"> + <xsl:param name="level"/> + <xsl:element name="h{$level - 1}"> + <xsl:apply-templates mode="common"/> + </xsl:element> </xsl:template> <!-- A common template for inline tags --> -<xsl:template match="strong|emphasize|text()" mode="common"> +<xsl:template match="line|strong|emphasize|embed-inline|custom-inline|anchor|link|text()" mode="common"> <xsl:choose> <!-- If a parent is paragraph --> <xsl:when test="boolean(parent::paragraph)"> @@ -38,7 +49,7 @@ <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:if test="($prevname = 'embed') or ($prevname = 'table') or ($prevname = 'ol') or ($prevname = 'ul') or ($prevname = 'literal') or ($prevname = 'custom')"> <xsl:call-template name='render_para' /> </xsl:if> </xsl:if> @@ -54,26 +65,46 @@ </xsl:template> <xsl:template name="render_para"> - <para> + <p> + <!-- Copy attributes of parent paragraph --> + <xsl:copy-of select="parent::paragraph/@*" /> <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:apply-templates mode="special" select="set:leading(following-sibling::node(),following-sibling::*[name() = 'embed' or name() = 'table' or name() = 'ol' or name() = 'ul' or name() = 'literal' or name() = 'custom'])"/> + </p> </xsl:template> - -<!-- TODO: add all block tags --> -<xsl:template match="embed|table" mode='common'> + +<!-- Specific templates for block tags --> +<xsl:template match="embed|table|tr|td|th|ol|ul|li|literal|custom" mode='common'> <xsl:copy> + <xsl:copy-of select="@*" /> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- Specific templates for inline tags --> +<xsl:template match="line" mode="special"> + <xsl:apply-templates mode="common"/> + <xsl:variable name="nextname" select="name(following-sibling::node()[1])" /> + <xsl:if test="boolean(count(following-sibling::node())) + and ($nextname != 'embed') and ($nextname != 'table') and ($nextname != 'ol') and ($nextname != 'ul') and ($nextname != 'literal') and ($nextname != 'custom')"> + <br /> + </xsl:if> +</xsl:template> + <xsl:template match="strong|emphasize" mode="special"> <xsl:copy> + <xsl:copy-of select="@*" /> <xsl:apply-templates/> </xsl:copy> </xsl:template> - + +<xsl:template match="link" mode="special"> + <xsl:copy> + <xsl:copy-of select="@*[name() != 'target']" /> + <xsl:apply-templates/> + </xsl:copy> +</xsl:template> + <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] Sun Nov 18 19:01:51 2007 @@ -1,6 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <section> - <paragraph>abc - <strong>def</strong><embed />ghi<strong>jkl</strong></paragraph> + <section> + <header>Header 1</header> + <paragraph class="pRed">abc + <strong>def</strong><embed src="eznode://123"/>ghi<strong>jkl</strong></paragraph> + <section> + <header>Header 1.1</header> + <paragraph>Text 1.1</paragraph> + </section> + </section> + <section> + <header>Header 2</header> + <paragraph><line>line 1</line><line>line 2</line></paragraph> + </section> </section> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components