diff options
Diffstat (limited to 'xhtml2odt/xsl/document-content')
| -rw-r--r-- | xhtml2odt/xsl/document-content/block.xsl | 169 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/html5.xsl | 122 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/ignore.xsl | 93 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/inline.xsl | 167 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/link.xsl | 127 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/lists.xsl | 130 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/media.xsl | 130 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/paragraph.xsl | 151 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/section.xsl | 80 | ||||
| -rw-r--r-- | xhtml2odt/xsl/document-content/tables.xsl | 334 | 
10 files changed, 1503 insertions, 0 deletions
| diff --git a/xhtml2odt/xsl/document-content/block.xsl b/xhtml2odt/xsl/document-content/block.xsl new file mode 100644 index 000000000..cac6873e5 --- /dev/null +++ b/xhtml2odt/xsl/document-content/block.xsl @@ -0,0 +1,169 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + + +<xsl:template match="h:blockquote"> +    <!-- special formatting is defined in paragraph --> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:hr"> +    <text:p text:style-name="Horizontal_20_Line"/> +</xsl:template> +<xsl:template match="h:hr" mode="inparagraph"/> + +<!-- +    Preformatted paragraphs management +--> +<xsl:template match="h:pre"> +    <text:p text:style-name="Preformatted_20_Text"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:p> +    <!-- The Preformatted_20_Text style has a margin-bottom of 0, so we add an +         empty line here --> +    <text:p text:style-name="Text_20_body"/> +</xsl:template> +<xsl:template match="h:pre" mode="inparagraph"/> + +<xsl:template match="h:pre//text()" mode="inparagraph"> +    <!-- Don't generate the last line break before the </pre> --> +    <xsl:variable name="content"> +        <xsl:choose> +            <xsl:when test="contains(., '
') +                            and position() = last() +                            and substring(., string-length(.)) = '
'"> +                <xsl:value-of select="substring(., 1, string-length(.)-1)"/> +            </xsl:when> +            <xsl:otherwise> +                <xsl:value-of select="."/> +            </xsl:otherwise> +        </xsl:choose> +    </xsl:variable> +    <!-- Now call the main template, which will handle the line-breaking --> +    <xsl:call-template name="pre.line"> +        <xsl:with-param name="content" select="$content"/> +    </xsl:call-template> +</xsl:template> + +<!-- +    this template splits newline-separated pararagraphs into multiple +    paragraphs +--> +<xsl:template name="pre.line"> +    <xsl:param name="content"/> +    <xsl:choose> +        <!-- This line-breaking manipulation is classical, e.g.: +             http://skew.org/xml/stylesheets/linefeed2br/ +        --> +        <xsl:when test="contains($content, '
')"> +            <!-- split in two --> +            <xsl:call-template name="pre.line"> +                <xsl:with-param name="content" select="substring-before($content, '
')"/> +            </xsl:call-template> +            <text:line-break/> +            <xsl:call-template name="pre.line"> +                <xsl:with-param name="content" select="substring-after($content, '
')"/> +            </xsl:call-template> +        </xsl:when> +        <xsl:otherwise> +            <!-- here we're on a single line, call pre.line.single to preserve +                 spaces --> +            <xsl:call-template name="pre.line.single"> +                <xsl:with-param name="content" select="string($content)"/> +            </xsl:call-template> +        </xsl:otherwise> +    </xsl:choose> +</xsl:template> + +<!-- This template escapes adjacent spaces --> +<xsl:template name="pre.line.single"> +    <xsl:param name="content"/> +    <xsl:choose> +        <xsl:when test="contains($content, '  ')"> +            <xsl:call-template name="pre.line.single"> +                <xsl:with-param name="content" select="substring-before($content, '  ')"/> +            </xsl:call-template> +            <text:s text:c="2"/> +            <xsl:call-template name="pre.line.single"> +                <xsl:with-param name="content" select="substring-after($content, '  ')"/> +            </xsl:call-template> +        </xsl:when> +        <xsl:when test="contains($content, '	')"> +            <xsl:call-template name="pre.line.single"> +                <xsl:with-param name="content" select="substring-before($content, '	')"/> +            </xsl:call-template> +            <text:tab/> +            <xsl:call-template name="pre.line.single"> +                <xsl:with-param name="content" select="substring-after($content, '	')"/> +            </xsl:call-template> +        </xsl:when> +        <xsl:otherwise> +            <xsl:value-of select="string($content)"/> +        </xsl:otherwise> +    </xsl:choose> +</xsl:template> + + +<xsl:template match="h:address"> +    <!-- special formatting is defined in paragraph --> +    <xsl:call-template name="paragraph"/> +</xsl:template> +<xsl:template match="h:address" mode="inparagraph"/> + +<xsl:template match="h:center"> +    <!-- special formatting is defined in paragraph --> +    <xsl:call-template name="paragraph"/> +</xsl:template> +<xsl:template match="h:center" mode="inparagraph"/> + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/html5.xsl b/xhtml2odt/xsl/document-content/html5.xsl new file mode 100644 index 000000000..aff901af7 --- /dev/null +++ b/xhtml2odt/xsl/document-content/html5.xsl @@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template match="h:section"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:header"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:footer"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:summary"> +    <!-- TODO: Add space on the left and right of the text --> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:article"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:nav"/> <!-- only keep the content --> + +<xsl:template match="h:aside"> +    <text:p text:style-name="Text_20_body"> +        <draw:frame draw:style-name="Marginalia" +                    text:anchor-type="paragraph" +                    svg:width="8.5cm" style:rel-width="50%"> +            <draw:text-box fo:min-height="0.5cm"> +                <xsl:apply-templates/> +            </draw:text-box> +        </draw:frame> +    </text:p> +</xsl:template> + +<xsl:template match="h:hgroup"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:time" mode="inparagraph"> +    <xsl:apply-templates mode="inparagraph"/> +</xsl:template> +<xsl:template match="h:time"/> + +<xsl:template match="h:mark" mode="inparagraph"> +    <!-- TODO: make the text background color yellow --> +    <xsl:apply-templates mode="inparagraph"/> +</xsl:template> + +<xsl:template match="h:canvas"/> + +<!-- TODO: include the source ? --> +<xsl:template match="h:audio"/> +<xsl:template match="h:video"/> +<xsl:template match="h:source"/> + +<!-- form elements --> +<xsl:template match="h:command|h:datalist|h:details|h:meter|h:output|h:progress|h:keygen"/> + +<!-- TODO: make a frame around it --> +<xsl:template match="h:figure"/> +<xsl:template match="h:figcaption"/> + +<xsl:template match="h:ruby|h:rt|h:rp" mode="inparagraph"> +    <xsl:apply-templates mode="inparagraph"/> +</xsl:template> +<xsl:template match="h:ruby|h:rt|h:rp"/> + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/ignore.xsl b/xhtml2odt/xsl/document-content/ignore.xsl new file mode 100644 index 000000000..d9c95bc00 --- /dev/null +++ b/xhtml2odt/xsl/document-content/ignore.xsl @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + +<xsl:template match="h:div"> +    <xsl:apply-templates/> +</xsl:template> +<xsl:template match="h:div" mode="inparagraph"> +    <xsl:apply-templates mode="inparagraph"/> +</xsl:template> + +<xsl:template match="h:html"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:head"/> + +<xsl:template match="h:body"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:span"/> +<xsl:template match="h:span" mode="inparagraph"> +    <xsl:choose> +        <xsl:when test="translate(@style,' ','') != ''"> +            <!-- leave the style handling to xsl/styles.xsl --> +            <xsl:copy> +                <xsl:copy-of select="@*"/> +                <xsl:apply-templates mode="inparagraph"/> +            </xsl:copy> +        </xsl:when> +        <xsl:otherwise> +            <xsl:apply-templates mode="inparagraph"/> +        </xsl:otherwise> +    </xsl:choose> +</xsl:template> + +<xsl:template match="h:script"/> +<xsl:template match="h:noscript"/> + +<xsl:template match="h:object"/> + +<xsl:template match="h:form"/> + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/inline.xsl b/xhtml2odt/xsl/document-content/inline.xsl new file mode 100644 index 000000000..54701b7ce --- /dev/null +++ b/xhtml2odt/xsl/document-content/inline.xsl @@ -0,0 +1,167 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template match="h:em|h:i"/> +<xsl:template match="h:em|h:i" mode="inparagraph"> +    <text:span text:style-name="emphasis"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:strong|h:b"/> +<xsl:template match="h:strong|h:b" mode="inparagraph"> +    <text:span text:style-name="strong"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:sup"/> +<xsl:template match="h:sup" mode="inparagraph"> +    <text:span text:style-name="sup"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:sub"/> +<xsl:template match="h:sub" mode="inparagraph"> +    <text:span text:style-name="sub"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:code|h:tt|h:samp|h:kbd"/> +<xsl:template match="h:code|h:tt|h:samp|h:kbd" mode="inparagraph"> +    <text:span text:style-name="Teletype"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:br"> +    <text:line-break/> +</xsl:template> +<xsl:template match="h:br" mode="inparagraph"> +    <text:line-break/> +</xsl:template> + +<xsl:template match="h:del"/> +<xsl:template match="h:del" mode="inparagraph"> +    <text:span text:style-name="strike"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:abbr|h:acronym"/> +<xsl:template match="h:abbr|h:acronym" mode="inparagraph"> +    <xsl:apply-templates mode="inparagraph"/> +    <xsl:variable name="footnotenum" +                  select="count(preceding::h:abbr) + count(preceding::h:acronym) + 1"/> +    <text:note text:note-class="footnote"> +        <xsl:attribute name="text:id"> +            <xsl:text>ftn</xsl:text> +            <xsl:value-of select="$footnotenum"/> +        </xsl:attribute> +        <text:note-citation> +            <xsl:value-of select="$footnotenum"/> +        </text:note-citation> +        <text:note-body> +            <text:p text:style-name="Footnote"> +                <xsl:value-of select="@title"/> +            </text:p> +        </text:note-body> +    </text:note> +</xsl:template> + +<xsl:template match="h:big"/> +<xsl:template match="h:big" mode="inparagraph"> +    <text:span text:style-name="big"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:small"/> +<xsl:template match="h:small" mode="inparagraph"> +    <text:span text:style-name="small"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:cite|h:dfn|h:var"/> +<xsl:template match="h:cite|h:dfn|h:var" mode="inparagraph"> +    <text:span text:style-name="Citation"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:q"/> +<xsl:template match="h:q" mode="inparagraph"> +    <xsl:text>"</xsl:text> +    <xsl:apply-templates mode="inparagraph"/> +    <xsl:text>"</xsl:text> +</xsl:template> + +<xsl:template match="h:ins"/> +<xsl:template match="h:ins" mode="inparagraph"> +    <text:span text:style-name="underline"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + +<xsl:template match="h:u"/> +<xsl:template match="h:u" mode="inparagraph"> +    <text:span text:style-name="underline"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:span> +</xsl:template> + + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/link.xsl b/xhtml2odt/xsl/document-content/link.xsl new file mode 100644 index 000000000..aa3c58266 --- /dev/null +++ b/xhtml2odt/xsl/document-content/link.xsl @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template match="h:a"> +    <xsl:call-template name="link"> +        <xsl:with-param name="mode" select="''"/> +    </xsl:call-template> +</xsl:template> +<xsl:template match="h:a" mode="inparagraph"> +    <xsl:call-template name="link"> +        <xsl:with-param name="mode" select="'inparagraph'"/> +    </xsl:call-template> +</xsl:template> + +<xsl:template name="link"> +    <xsl:param name="mode"/> +    <xsl:choose> +        <xsl:when test="h:img"> +            <draw:a> +                <xsl:call-template name="link-content"> +                    <xsl:with-param name="mode" select="$mode"/> +                </xsl:call-template> +            </draw:a> +        </xsl:when> +        <xsl:otherwise> +            <text:a> +                <xsl:call-template name="link-content"> +                    <xsl:with-param name="mode" select="$mode"/> +                </xsl:call-template> +            </text:a> +        </xsl:otherwise> +    </xsl:choose> +</xsl:template> + +<xsl:template name="link-content"> +    <xsl:param name="mode"/> +    <xsl:attribute name="xlink:type"><xsl:text>simple</xsl:text></xsl:attribute> +    <xsl:attribute name="xlink:href"> +        <xsl:choose> +            <xsl:when test="contains(@href, '#') and substring-before(@href,'#') = $url"> +                <xsl:text>#</xsl:text><xsl:value-of select="substring-after(@href,'#')"/> +            </xsl:when> +            <xsl:otherwise> +                <xsl:value-of select="@href"/> +            </xsl:otherwise> +        </xsl:choose> +    </xsl:attribute> +    <xsl:choose> +        <xsl:when test="@id"> +            <text:bookmark-start> +                <xsl:attribute name="text:name"> +                    <xsl:value-of select="@id"/> +                </xsl:attribute> +            </text:bookmark-start> +        </xsl:when> +    </xsl:choose> +    <xsl:choose> +        <xsl:when test="$mode = 'inparagraph'"> +            <xsl:apply-templates mode="inparagraph"/> +        </xsl:when> +        <xsl:otherwise> +            <xsl:apply-templates/> +        </xsl:otherwise> +    </xsl:choose> +    <xsl:choose> +        <xsl:when test="@id"> +            <text:bookmark-end> +                <xsl:attribute name="text:name"> +                    <xsl:value-of select="@id"/> +                </xsl:attribute> +            </text:bookmark-end> +        </xsl:when> +    </xsl:choose> +</xsl:template> + + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/lists.xsl b/xhtml2odt/xsl/document-content/lists.xsl new file mode 100644 index 000000000..aa0d8eb05 --- /dev/null +++ b/xhtml2odt/xsl/document-content/lists.xsl @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template match="h:ul" mode="inparagraph"/> +<xsl:template match="h:ul"> +    <xsl:param name="nolists" select="false()"/> +    <!-- No lists inside lists (handled separately, see below) --> +    <xsl:if test="not($nolists)"> +        <text:list text:style-name="List_20_1"> +            <xsl:apply-templates select="h:li"/> +        </text:list> +    </xsl:if> +</xsl:template> + + +<xsl:template match="h:ol" mode="inparagraph"/> +<xsl:template match="h:ol"> +    <xsl:param name="nolists" select="false()"/> +    <!-- No lists inside lists (handled separately, see below) --> +    <xsl:if test="not($nolists)"> +        <text:list text:style-name="Numbering_20_1"> +            <xsl:apply-templates select="h:li" /> +        </text:list> +    </xsl:if> +</xsl:template> + +<!-- li --> + +<xsl:template match="h:li" mode="inparagraph"/> +<xsl:template match="h:li"> +    <text:list-item> +        <text:p> +            <xsl:attribute name="text:style-name"> +                <xsl:text>list-item</xsl:text> +                <xsl:choose> +                    <xsl:when test="parent::h:ul"><xsl:text>-bullet</xsl:text></xsl:when> +                    <xsl:when test="parent::h:ol"><xsl:text>-number</xsl:text></xsl:when> +                    <xsl:otherwise></xsl:otherwise> +                </xsl:choose> +            </xsl:attribute> +            <xsl:apply-templates select="child::node()" mode="inparagraph"> +                <!-- sublists must be after the </text:p> --> +                <xsl:with-param name="nolists" select="true()"/> +            </xsl:apply-templates> +        </text:p> +        <xsl:apply-templates select="h:ul|h:ol|h:pre|h:blockquote"/> +    </text:list-item> +</xsl:template> + + +<!-- Definition lists --> +<xsl:template match="h:dl" mode="inparagraph"/> +<xsl:template match="h:dl"> +    <!--<xsl:apply-templates select="h:dt"/>--> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:dt" mode="inparagraph"/> +<xsl:template match="h:dt"> +    <xsl:call-template name="paragraph"/> +    <!-- +    <text:p text:style-name="Definition_20_Term"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:p> +    <xsl:apply-templates select="following-sibling::h:dd[position()=1]"/> +    --> +</xsl:template> + +<xsl:template match="h:dd" mode="inparagraph"/> +<xsl:template match="h:dd"> +    <xsl:call-template name="paragraph"/> +    <!-- +    <text:p text:style-name="Definition_20_Description"> +        <xsl:apply-templates mode="inparagraph"/> +    </text:p> +    --> +</xsl:template> + + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/media.xsl b/xhtml2odt/xsl/document-content/media.xsl new file mode 100644 index 000000000..5397a06df --- /dev/null +++ b/xhtml2odt/xsl/document-content/media.xsl @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template match="h:img"> +    <text:p text:style-name="Text_20_body"> +        <xsl:call-template name="image"/> +    </text:p> +</xsl:template> +<xsl:template match="h:img" mode="inparagraph"> +    <xsl:call-template name="image"/> +</xsl:template> + +<xsl:template name="image"> + +    <!-- @align                                                  --> +    <!-- @contentwidth                                           --> +    <!-- @contentheight                                          --> +    <!-- @fileref                                                --> +    <!-- @format                                                 --> +    <!-- @scale                                                  --> +    <!-- @scalefit                                               --> +    <!-- @valign                                                 --> +    <!-- @width                                                  --> +    <!-- @depth                                                  --> + +    <xsl:element name="draw:frame"> + +        <xsl:choose> +            <xsl:when test="substring-before(@width,'cm') < $img_inline_threshold +                            and substring-before(@height,'cm') < $img_inline_threshold"> +                <xsl:attribute name="text:anchor-type">as-char</xsl:attribute> +                <xsl:attribute name="draw:style-name">image-inline</xsl:attribute> +            </xsl:when> +            <xsl:when test="contains(@style,'float:') and contains(@style,'left')"> +                <xsl:attribute name="text:anchor-type">paragraph</xsl:attribute> +                <xsl:attribute name="draw:style-name">image-left</xsl:attribute> +            </xsl:when> +            <xsl:when test="contains(@style,'float:') and contains(@style,'right')"> +                <xsl:attribute name="text:anchor-type">paragraph</xsl:attribute> +                <xsl:attribute name="draw:style-name">image-right</xsl:attribute> +            </xsl:when> +            <xsl:otherwise> +                <xsl:attribute name="text:anchor-type">paragraph</xsl:attribute> +                <xsl:attribute name="draw:style-name">image-center</xsl:attribute> +            </xsl:otherwise> +        </xsl:choose> + +        <xsl:attribute name="draw:name">imageobject-<xsl:value-of select="generate-id()"/></xsl:attribute> + +        <xsl:choose> +            <xsl:when test="@width and @height"> +                <xsl:attribute name="svg:width"><xsl:value-of select="@width"/></xsl:attribute> +                <xsl:attribute name="svg:height"><xsl:value-of select="@height"/></xsl:attribute> +            </xsl:when> +            <xsl:otherwise> +                <!-- In OpenDocument svg:width and height must be defined. Use defaults here --> +                <xsl:attribute name="svg:width"><xsl:value-of select="$img_default_width"/></xsl:attribute> +                <xsl:attribute name="svg:height"><xsl:value-of select="$img_default_height"/></xsl:attribute> +            </xsl:otherwise> +        </xsl:choose> + +        <xsl:attribute name="svg:y">0.20cm</xsl:attribute> + +        <xsl:attribute name="draw:z-index">1</xsl:attribute> +        <xsl:element name="draw:image"> +            <xsl:attribute name="xlink:href"><xsl:value-of select="@src"/></xsl:attribute> +            <xsl:attribute name="xlink:type">simple</xsl:attribute> +            <xsl:attribute name="xlink:show">embed</xsl:attribute> +            <xsl:attribute name="xlink:actuate">onLoad</xsl:attribute> +        </xsl:element> + +        <xsl:element name="svg:title"><xsl:value-of select="@alt"/></xsl:element> + +    </xsl:element> + +</xsl:template> + + + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/paragraph.xsl b/xhtml2odt/xsl/document-content/paragraph.xsl new file mode 100644 index 000000000..b9ffbec55 --- /dev/null +++ b/xhtml2odt/xsl/document-content/paragraph.xsl @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template match="h:p"> +    <xsl:call-template name="paragraph"/> +</xsl:template> +<xsl:template match="h:p" mode="inparagraph"> +    <xsl:apply-templates mode="inparagraph"/> +</xsl:template> + +<xsl:template name="paragraph"> +    <xsl:choose> +        <xsl:when test=" +            child::h:ul| +            child::h:ol| +            child::h:blockquote| +            child::h:pre | +            child::h:dl | +            child::h:div +            "> +            <xsl:for-each select=" +                    child::h:ul | +                    child::h:ol | +                    child::h:blockquote | +                    child::h:pre | +                    child::h:dl | +                    child::h:div +                    "> +                <!-- Paragraph with the text before --> +                <xsl:if test="preceding-sibling::node()"> +                    <xsl:call-template name="paragraph-content"> +                        <xsl:with-param name="subject" select="preceding-sibling::node()"/> +                    </xsl:call-template> +                </xsl:if> +                <!-- Create the block-type element --> +                <xsl:apply-templates select="."/> +                <!-- Paragraph with the text after --> +                    <xsl:if test="following-sibling::node()"> +                    <xsl:call-template name="paragraph-content"> +                        <xsl:with-param name="subject" select="following-sibling::node()"/> +                    </xsl:call-template> +                </xsl:if> +            </xsl:for-each> +        </xsl:when> +        <xsl:otherwise> +            <xsl:call-template name="paragraph-content"> +                <xsl:with-param name="subject" select="node()"/> +            </xsl:call-template> +        </xsl:otherwise> +    </xsl:choose> +</xsl:template> + + +<xsl:template name="paragraph-content"> + +    <xsl:param name="subject"/> + +    <text:p> + +        <xsl:attribute name="text:style-name"> +            <xsl:choose> +                <!-- those two seem unnecessary, it's handled in lists.xsl --> +                <xsl:when test="$subject/parent::h:ul"> +                    <xsl:text>list-item-bullet</xsl:text> +                </xsl:when> +                <xsl:when test="$subject/parent::h:ol"> +                    <xsl:text>list-item-number</xsl:text> +                </xsl:when> +                <xsl:when test="$subject/../parent::h:blockquote">Quotations</xsl:when> +                <xsl:when test="contains(@style,'text-align:') and contains(@style,'left')">left</xsl:when> +                <xsl:when test="contains(@style,'text-align:') and contains(@style,'center')">center</xsl:when> +                <xsl:when test="contains(@style,'text-align:') and contains(@style,'right')">right</xsl:when> +                <xsl:when test="contains(@style,'text-align:') and contains(@style,'justify')">justify</xsl:when> +                <xsl:when test="$subject/self::h:address or (name($subject) = '' and $subject/parent::h:address)">Sender</xsl:when> +                <xsl:when test="$subject/self::h:center or (name($subject) = '' and $subject/parent::h:center)">center</xsl:when> +                <xsl:when test="$subject/self::h:th or (name($subject) = '' and $subject/parent::h:th)">Table_20_Heading</xsl:when> +                <xsl:when test="$subject/self::h:td or (name($subject) = '' and $subject/parent::h:td)">Table_20_Contents</xsl:when> +                <xsl:when test="$subject/self::h:dt or (name($subject) = '' and $subject/parent::h:dt)">Definition_20_Term</xsl:when> +                <xsl:when test="$subject/self::h:dd or (name($subject) = '' and $subject/parent::h:dd)">Definition_20_Description</xsl:when> +                <xsl:otherwise>Text_20_body</xsl:otherwise> +            </xsl:choose> +        </xsl:attribute> + +        <xsl:for-each select="$subject"> +            <xsl:choose> +                <xsl:when test="name() = ''"> +                    <!-- text node --> +                    <xsl:value-of select="string()"/> +                </xsl:when> +                <xsl:otherwise> +                    <xsl:apply-templates select="." mode="inparagraph"/> +                </xsl:otherwise> +            </xsl:choose> +        </xsl:for-each> + +    </text:p> + +</xsl:template> + + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/section.xsl b/xhtml2odt/xsl/document-content/section.xsl new file mode 100644 index 000000000..72f1479f2 --- /dev/null +++ b/xhtml2odt/xsl/document-content/section.xsl @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template name="section" match="h:h1|h:h2|h:h3|h:h4|h:h5|h:h6"> + +    <!-- compute level of section --> +    <xsl:variable name="level"> +        <xsl:value-of select="substring-after(local-name(.),'h') - $heading_minus_level"/> +    </xsl:variable> + +    <xsl:comment> +        <xsl:text>section level </xsl:text><xsl:value-of select="$level"/> +    </xsl:comment> + +    <text:h> +        <xsl:attribute name="text:style-name"><xsl:text>Heading_20_</xsl:text> +            <xsl:value-of select="$level"/> +        </xsl:attribute> +        <xsl:attribute name="text:outline-level"> +            <xsl:value-of select="$level"/> +        </xsl:attribute> + +        <xsl:apply-templates mode="inparagraph"/> + +    </text:h> + +</xsl:template> + + +</xsl:stylesheet> diff --git a/xhtml2odt/xsl/document-content/tables.xsl b/xhtml2odt/xsl/document-content/tables.xsl new file mode 100644 index 000000000..a063f6bfd --- /dev/null +++ b/xhtml2odt/xsl/document-content/tables.xsl @@ -0,0 +1,334 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +    xhtml2odt - XHTML to ODT XML transformation. +    Copyright (C) 2009 Aurelien Bompard +    Inspired by the work on docbook2odt, by Roman Fordinal +    http://open.comsultia.com/docbook2odf/ + +    License: LGPL v2.1 or later <http://www.gnu.org/licenses/lgpl-2.1.html> + +    This library is free software; you can redistribute it and/or +    modify it under the terms of the GNU Lesser General Public +    License as published by the Free Software Foundation; either +    version 2.1 of the License, or (at your option) any later version. + +    This library is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +    Lesser General Public License for more details. + +    You should have received a copy of the GNU Lesser General Public +    License along with this library; if not, write to the Free Software +    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +    MA  02110-1301  USA + +--> +<xsl:stylesheet +    xmlns:h="http://www.w3.org/1999/xhtml" +    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" +    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +    xmlns:dc="http://purl.org/dc/elements/1.1/" +    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" +    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" +    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" +    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" +    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" +    xmlns:xlink="http://www.w3.org/1999/xlink" +    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" +    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" +    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" +    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" +    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" +    xmlns:math="http://www.w3.org/1998/Math/MathML" +    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" +    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" +    xmlns:dom="http://www.w3.org/2001/xml-events" +    xmlns:xforms="http://www.w3.org/2002/xforms" +    xmlns:xsd="http://www.w3.org/2001/XMLSchema" +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" +    version="1.0"> + + +<xsl:template name="table.number"> +    <!-- compute number of section --> +    <xsl:value-of select="count(preceding::h:table)+1"/> +</xsl:template> + +<xsl:template match="h:table"> +    <table:table table:style-name="table-default"> +        <table:table-column> +            <xsl:attribute name="table:number-columns-repeated"> +                <xsl:value-of select="count(descendant::h:tr[1]/h:th|descendant::h:tr[1]/h:td)"/> +            </xsl:attribute> +        </table:table-column> +        <!--<xsl:attribute name="table:name"></xsl:attribute>--> +        <xsl:apply-templates/> +        <xsl:apply-templates select="h:tfoot/*"/> +    </table:table> +    <xsl:if test="h:caption"> +        <xsl:variable name="number"> +            <xsl:call-template name="table.number"/> +        </xsl:variable> +        <text:p text:style-name="Caption"> +            <xsl:text>Table </xsl:text> +            <text:sequence text:ref-name="refTable0" text:name="Table" +                           text:formula="ooow:Table+1" style:num-format="1"> +                <xsl:value-of select="$number"/> +            </text:sequence> +            <xsl:text>: </xsl:text><xsl:value-of select="h:caption"/> +        </text:p> +    </xsl:if> +</xsl:template> + +<xsl:template match="h:table/h:caption"/> + +<xsl:template match="h:thead"> +    <!-- <table:table-header-rows> handled in <th> --> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:tfoot"> +    <!-- handled above in h:table --> +</xsl:template> + +<xsl:template match="h:tbody"> +    <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="h:tr"> +    <xsl:choose> +        <!-- this is header --> +        <xsl:when test="h:th"> +            <table:table-header-rows> +                <xsl:call-template name="make-table-row"/> +            </table:table-header-rows> +        </xsl:when> +        <xsl:otherwise> +            <xsl:call-template name="make-table-row"/> +        </xsl:otherwise> +    </xsl:choose> +</xsl:template> + +<xsl:template name="make-table-row"> +    <table:table-row> +        <!-- fill covered-table-cells for rowspans on the first column --> +        <xsl:for-each select="preceding-sibling::h:tr/*[position() = 1 and @rowspan != 1]"> +            <xsl:call-template name="make-rowspan-covered-table-cell"> +                <xsl:with-param name="vertical-position"> +                    <xsl:value-of select="count(preceding-sibling::h:tr) + 1"/> +                </xsl:with-param> +            </xsl:call-template> +        </xsl:for-each> +        <!-- do the cell handling now --> +        <xsl:apply-templates/> +    </table:table-row> +</xsl:template> + +<xsl:template match="h:th"> +    <xsl:call-template name="table-cell"> +        <xsl:with-param name="horizontal-position" select="count(preceding-sibling::*) + 1"/> +        <xsl:with-param name="horizontal-count" select="count(../*)"/> +        <xsl:with-param name="vertical-position" select="count(../preceding-sibling::h:tr) + 1"/> +        <xsl:with-param name="vertical-count" select="count(ancestor::h:table[1]/descendant::h:tr)"/> +    </xsl:call-template> +</xsl:template> + +<xsl:template match="h:td"> +    <xsl:call-template name="table-cell"> +        <xsl:with-param name="horizontal-position" select="count(preceding-sibling::*) + 1"/> +        <xsl:with-param name="horizontal-count" select="count(../*)"/> +        <xsl:with-param name="vertical-position" select="count(../preceding-sibling::h:tr) +                                                       + count(ancestor::h:table[1]/descendant::h:thead/h:tr) +                                                       + 1"/> +        <xsl:with-param name="vertical-count" select="count(ancestor::h:table[1]/descendant::h:tr)"/> +    </xsl:call-template> +</xsl:template> + + +<!-- table cell --> + +<xsl:template name="table-cell"> + +    <xsl:param name="horizontal-position" /> +    <xsl:param name="horizontal-count" /> +    <xsl:param name="vertical-position" /> +    <xsl:param name="vertical-count" /> + +    <xsl:comment>horizontal-position=<xsl:value-of select="$horizontal-position"/></xsl:comment> +    <xsl:comment>horizontal-count=<xsl:value-of select="$horizontal-count"/></xsl:comment> +    <xsl:comment>vertical-position=<xsl:value-of select="$vertical-position"/></xsl:comment> +    <xsl:comment>vertical-count=<xsl:value-of select="$vertical-count"/></xsl:comment> + +    <table:table-cell office:value-type="string"> + +        <xsl:attribute name="table:style-name"> +            <xsl:text>table-default.cell-</xsl:text> +            <!-- prefix --> +            <xsl:if test="self::h:th and $vertical-position = 1"> +                <xsl:text>H-</xsl:text> +            </xsl:if> +            <xsl:if test="parent::h:tr/parent::h:tfoot"> +                <xsl:text>F-</xsl:text> +            </xsl:if> +            <!-- postfix defined by cell position --> +            <!-- +                __________ +                |A1|B1|C1| +                |A2|B2|C2| +                |A3|B3|C3| +                ^^^^^^^^^^ +                __________ +                |A4|B4|C4| +                ^^^^^^^^^^ +                ____ +                |C1| +                |C2| +                |C3| +                ^^^^ +            --> +            <xsl:choose> + +                <!-- single --> +                <xsl:when test="$horizontal-count = 1 and $vertical-count = 1"> +                    <xsl:text>single</xsl:text> +                </xsl:when> + +                <!-- A4 --> +                <xsl:when test="$horizontal-position = 1 and $vertical-count = 1"> +                    <xsl:text>A4</xsl:text> +                </xsl:when> +                <!-- C4 --> +                <xsl:when test="$horizontal-position = $horizontal-count and $vertical-count = 1"> +                    <xsl:text>C4</xsl:text> +                </xsl:when> +                <!-- B4 --> +                <xsl:when test="$vertical-count = 1"> +                    <xsl:text>B4</xsl:text> +                </xsl:when> + +                <!-- tfoot A --> +                <xsl:when test="ancestor::h:tfoot and $horizontal-position = 1"> +                    <xsl:text>A3</xsl:text> +                </xsl:when> +                <!-- tfoot B --> +                <xsl:when test="ancestor::h:tfoot and $horizontal-position = $horizontal-count"> +                    <xsl:text>C3</xsl:text> +                </xsl:when> +                <!-- tfoot C --> +                <xsl:when test="ancestor::h:tfoot"> +                    <xsl:text>B3</xsl:text> +                </xsl:when> + +                <!-- A3 --> +                <xsl:when test="$horizontal-position = 1 and $horizontal-count != 1 and $vertical-position = $vertical-count"> +                    <xsl:text>A3</xsl:text> +                </xsl:when> +                <!-- C3 --> +                <xsl:when test="$horizontal-position = $horizontal-count and $vertical-position = $vertical-count"> +                    <xsl:text>C3</xsl:text> +                </xsl:when> +                <!-- B3 --> +                <xsl:when test="$vertical-position = $vertical-count"> +                    <xsl:text>B3</xsl:text> +                </xsl:when> + +                <!-- A1 --> +                <xsl:when test="$horizontal-position = 1 and $horizontal-position != $horizontal-count and $vertical-position = 1"> +                    <xsl:text>A1</xsl:text> +                </xsl:when> +                <!-- C1 --> +                <xsl:when test="$horizontal-position = $horizontal-count and $vertical-position = 1"> +                    <xsl:text>C1</xsl:text> +                </xsl:when> +                <!-- B1 --> +                <xsl:when test="$vertical-position = 1"> +                    <xsl:text>B1</xsl:text> +                </xsl:when> + +                <!-- A2 --> +                <xsl:when test="$horizontal-position = 1 and $horizontal-position != $horizontal-count"> +                    <xsl:text>A2</xsl:text> +                </xsl:when> +                <!-- C2 --> +                <xsl:when test="$horizontal-position = $horizontal-count"> +                    <xsl:text>C2</xsl:text> +                </xsl:when> + +                <!-- all other cells --> +                <xsl:otherwise> +                    <xsl:text>B2</xsl:text> +                </xsl:otherwise> + +            </xsl:choose> + +        </xsl:attribute> + +        <xsl:if test="@colspan and @colspan != 1"> +            <xsl:attribute name="table:number-columns-spanned"> +                <xsl:value-of select="@colspan"/> +            </xsl:attribute> +        </xsl:if> + +        <xsl:if test="@rowspan and @rowspan != 1"> +            <xsl:attribute name="table:number-rows-spanned"> +                <xsl:value-of select="@rowspan"/> +            </xsl:attribute> +        </xsl:if> + +        <!-- Content --> +        <xsl:choose> +            <xsl:when test="h:table"> <!-- nested tables --> +                <xsl:apply-templates/> +            </xsl:when> +            <xsl:otherwise> +                <xsl:call-template name="paragraph"/> +            </xsl:otherwise> +        </xsl:choose> + +    </table:table-cell> + +    <!-- fill covered-table-cells for colspans --> +    <xsl:if test="@colspan and @colspan != 1"> +        <xsl:call-template name="make-covered-table-cell"> +            <xsl:with-param name="num"> +                <xsl:value-of select="@colspan"/> +            </xsl:with-param> +        </xsl:call-template> +    </xsl:if> + +    <!-- fill covered-table-cells for rowspans --> +    <xsl:for-each select="../preceding-sibling::h:tr/*[position() = $horizontal-position + 1 and @rowspan != 1]"> +        <xsl:call-template name="make-rowspan-covered-table-cell"> +            <xsl:with-param name="vertical-position"> +                <xsl:value-of select="$vertical-position"/> +            </xsl:with-param> +        </xsl:call-template> +    </xsl:for-each> + +</xsl:template> + + +<xsl:template name="make-covered-table-cell"> +    <xsl:param name="num"/> +    <xsl:if test="$num > 1"> +        <table:covered-table-cell/> +        <xsl:call-template name="make-covered-table-cell"> +            <xsl:with-param name="num"> +                <xsl:value-of select="$num - 1"/> +            </xsl:with-param> +        </xsl:call-template> +    </xsl:if> +</xsl:template> + +<xsl:template name="make-rowspan-covered-table-cell"> +    <xsl:param name="vertical-position"/> +    <xsl:variable name="spanned-vertical-position" select="count(../preceding-sibling::h:tr) + 1"/> +    <xsl:if test="$spanned-vertical-position + @rowspan - 1 >= $vertical-position"> +        <table:covered-table-cell/> +    </xsl:if> +</xsl:template> + + +</xsl:stylesheet> | 
