[Zope3-checkins] CVS: zopeproducts/xslt_examples - README.txt:1.1 __init__.py:1.1 configure.zcml:1.1 example.xml:1.1 ooadapter.py:1.1 ooo2html.xsl:1.1 ooview.py:1.1
Martijn Faassen
m.faassen@vet.uu.nl
Sun, 13 Apr 2003 12:31:50 -0400
Update of /cvs-repository/zopeproducts/xslt_examples
In directory cvs.zope.org:/tmp/cvs-serv30645
Added Files:
README.txt __init__.py configure.zcml example.xml ooadapter.py
ooo2html.xsl ooview.py
Log Message:
Checked in a fledgeling example of how to create an adapter and view
that display contents of an XML document as HTML, transformed by
an XSLT sheet.
=== Added File zopeproducts/xslt_examples/README.txt ===
XSLT Example
============
What this example does:
* Sets up a view for Open Office documents -- that is, XML Documents
that declare they contain Open Office writer XML that displays the
document content as HTML.
* The view works by using an adapter to do the transformation work using
XSLT.
The view gets set up as the default view of XML documents which
contain OpenOffice XML. That is, save from the OpenOffice writer,
unzip the save file, take the 'content.xml' file and put it into an
XML Document in Zope 3. In addition, add the following two attributes
to the root node of the XML to signal to Zope that it is indeed an
OpenOffice document:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://openoffice.org/hypothetical/document.xsd"
An example of such an XML file is included as 'example.xml'. If you
place it into an XML Document looking at its public view (or
'view.html' alternatively) will show you the contents transformed to
HTML.
=== Added File zopeproducts/xslt_examples/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: __init__.py,v 1.1 2003/04/13 16:31:49 faassen Exp $
"""
=== Added File zopeproducts/xslt_examples/configure.zcml ===
<zopeConfigure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:zopexml="http://namespaces.zope.org/zope-xml">
<!-- First, we define two schema interfaces. They don't have to exist at their
specified URIs for this application (they have to for more advanced
uses) -->
<zopexml:schemaInterface
uri="http://openoffice.org/hypothetical/document.xsd" />
<zopexml:schemaInterface
uri="http://www.w3.org/hypothetical/html" />
<adapter
for="http://openoffice.org/hypothetical/document.xsd"
provides="http://www.w3.org/hypothetical/html"
factory=".ooadapter.OOAdapter"
permission="zope.View" />
<browser:pages
for="http://openoffice.org/hypothetical/document.xsd"
permission="zope.View"
class=".ooview.OOView">
<browser:page
name="view.html"
attribute="render" />
</browser:pages>
<browser:defaultView
for="http://openoffice.org/hypothetical/document.xsd"
name="view.html" />
</zopeConfigure>
=== Added File zopeproducts/xslt_examples/example.xml ===
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE office:document-content PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd"><office:document-content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://openoffice.org/hypothetical/document.xsd" xmlns:office="http://openoffice.org/2000/office" xmlns:style="http://openoffice.org/2000/style" xmlns:text="http://openoffice.org/2000/text" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:number="http://openoffice.org/2000/datastyle" xmlns:svg="http://www.w3.org/2000/svg" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dr3d="http://openoffice.org/2000/dr3d" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="http://openoffice.org/2000/form" xmlns:script="http://openoffice.org/2000/script" office:class="text" office:version="1.0"><office:script/><office:font-decls><style:font-de!
cl style:name="Arial Unicode MS" fo:font-family="'Arial Unicode MS'" style:font-pitch="variable"/><style:font-decl style:name="HG Mincho Light J" fo:font-family="'HG Mincho Light J'" style:font-pitch="variable"/><style:font-decl style:name="Thorndale" fo:font-family="Thorndale" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-decl style:name="Albany" fo:font-family="Albany" style:font-family-generic="swiss" style:font-pitch="variable"/></office:font-decls><office:automatic-styles/><office:body><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:h text:style-name="Heading 1" text:level="1">Hello world</text:h><text:p text:style-name="Standard"/><text:!
p text:style-name="Standard">This OpenOffice document is automatically transformed to HTML by Zope 3's fledgling XML architecture.</text:p></office:body></office:document-content>
=== Added File zopeproducts/xslt_examples/ooadapter.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: ooadapter.py,v 1.1 2003/04/13 16:31:49 faassen Exp $
"""
import os.path
from zopeproducts.xslt.sheet import XSLTSheet
def readfile(filename):
f = open(os.path.join(os.path.dirname(__file__), filename), 'r')
text = f.read()
f.close()
return text
OOAdapter = XSLTSheet(readfile('ooo2html.xsl'))
=== Added File zopeproducts/xslt_examples/ooo2html.xsl ===
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:office="http://openoffice.org/2000/office"
xmlns:style="http://openoffice.org/2000/style"
xmlns:text="http://openoffice.org/2000/text"
xmlns:table="http://openoffice.org/2000/table"
xmlns:draw="http://openoffice.org/2000/drawing">
<!--
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
When run through a XSLT processor, this style sheet will convert OpenOffice.org XML
documents to rather clean (X)HTML which will still be manually editable.
Written by Philipp "philiKON" von Weitershausen (philikon@philikon.de)
$Id: ooo2html.xsl,v 1.1 2003/04/13 16:31:49 faassen Exp $
-->
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<xsl:apply-templates />
</html>
</xsl:template>
<xsl:template match="//office:body">
<body>
<xsl:apply-templates />
</body>
</xsl:template>
<!-- Text Content ... pages 123ff file format documentation-->
<!-- Paragraph -->
<xsl:template match="//text:p">
<p>
<xsl:if test="@text:style-name"> <!-- if this attribute is there, it refers to a style definition -->
<xsl:call-template name="apply-style" /> <!-- thus, add CSS styles -->
</xsl:if>
<xsl:apply-templates />
</p>
</xsl:template>
<!-- Space -->
<xsl:template match="//text:s">
<xsl:for-each select="@text:c"> <!-- XXX range() function or something... -->
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
<!-- Tab Stop-->
<xsl:template match="//text:tab-stop">
<xsl:text> </xsl:text>
</xsl:template>
<!-- Span -->
<xsl:template match="//text:span">
<span>
<xsl:if test="@text:style-name"> <!-- if this attribute is there, it refers to a style definition -->
<xsl:call-template name="apply-style" /> <!-- thus, add CSS styles -->
</xsl:if>
<xsl:apply-templates />
</span>
</xsl:template>
<!-- Link -->
<xsl:template match="//text:a">
<a>
<xsl:attribute name="href"><xsl:value-of select="@xlink:href" /></xsl:attribute>
<xsl:if test="@office:target-frame-name">
<xsl:attribute name="target"><xsl:value-of select="@office:target-frame-name" /></xsl:attribute>
</xsl:if>
<xsl:apply-templates />
</a>
</xsl:template>
<!-- Bookmark -->
<xsl:template match="//text:bookmark">
<a id="{@text:name}" />
</xsl:template>
<!-- Ordered List -->
<xsl:template match="//text:ordered-list">
<ol>
<xsl:apply-templates />
</ol>
</xsl:template>
<!-- Unordered List -->
<xsl:template match="//text:unordered-list">
<ul>
<xsl:apply-templates />
</ul>
</xsl:template>
<!-- Ordered List -->
<xsl:template match="//text:list-item">
<li><xsl:apply-templates /></li>
</xsl:template>
<!-- Line break -->
<xsl:template match="//text:line-break">
<br />
</xsl:template>
<!-- Table Content ... pages 261ff file format documentation-->
<!-- Table -->
<xsl:template match="//table:table">
<table>
<xsl:if test="@table:style-name"> <!-- if this attribute is there, it refers to a style definition -->
<xsl:call-template name="apply-style"> <!-- thus, add CSS styles -->
<xsl:with-param name="style-name" select="@table:style-name" />
</xsl:call-template>
</xsl:if>
<xsl:apply-templates />
</table>
</xsl:template>
<!-- Table Header Rows -->
<xsl:template match="//table:table-header-rows">
<xsl:apply-templates mode="header-row" />
</xsl:template>
<!-- Table Row -->
<xsl:template match="//table:table-row">
<tr>
<xsl:if test="@table:style-name"> <!-- if this attribute is there, it refers to a style definition -->
<xsl:call-template name="apply-style"> <!-- thus, add CSS styles -->
<xsl:with-param name="style-name" select="@table:style-name" />
</xsl:call-template>
</xsl:if>
<xsl:apply-templates />
</tr>
</xsl:template>
<!-- Table Cell -->
<xsl:template match="//table:table-cell">
<td>
<xsl:if test="@table:style-name"> <!-- if this attribute is there, it refers to a style definition -->
<xsl:call-template name="apply-style"> <!-- thus, add CSS styles -->
<xsl:with-param name="style-name" select="@table:style-name" />
</xsl:call-template>
</xsl:if>
<xsl:apply-templates />
</td>
</xsl:template>
<xsl:template match="//table:table-cell" mode="header-row">
<th>
<xsl:if test="@table:style-name"> <!-- if this attribute is there, it refers to a style definition -->
<xsl:call-template name="apply-style"> <!-- thus, add CSS styles -->
<xsl:with-param name="style-name" select="@table:style-name" />
</xsl:call-template>
</xsl:if>
<xsl:apply-templates />
</th>
</xsl:template>
<!-- Draw Content ... pages 362ff file format documentation-->
<xsl:template match="//draw:image">
<img alt="{@draw:name}" src="{@xlink:href}" />
</xsl:template>
<!-- Styles ... used everywhere -->
<xsl:template name="apply-style">
<!-- This template is called by text:p and text:span templates in order to
insert a style attribute with CSS styles -->
<xsl:param name="style-name" select="@text:style-name" />
<xsl:attribute name="style">
<xsl:apply-templates select="//style:style[@style:name=$style-name]/style:properties/@*" mode="style" />
</xsl:attribute>
</xsl:template>
<!-- Format Attributes -->
<xsl:template match="@fo:*|@style:width" mode="style">
<!-- The following attributes in the XSL format (fo) namespace are used by OpenOffice.org
but don't seem to be part of CSS. This may lead to not 100% valid CSS.
* language
* country
* text-shadow
* text-align-last
* hyphenate
* hyphenation-keep
* hyphenation-remain-char-count
* hyphenation-push-char-count
* hyphenation-ladder-count
* break-before
* break-after
-->
<xsl:value-of select="local-name()" /><xsl:text>:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@fo:text-align" mode="style">
<xsl:if test=".='start'" >text-align:left; </xsl:if>
<xsl:if test=".='center'" >text-align:center; </xsl:if>
<xsl:if test=".='end'" >text-align:right; </xsl:if>
<xsl:if test=".='justify'" >text-align:justify; </xsl:if>
</xsl:template>
<!-- Style Attributes -->
<xsl:template match="@style:font-name" mode="style">
<xsl:text>font-family:</xsl:text><xsl:value-of select="local-name()" /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@style:text-underline" mode="style">
<xsl:text>text-decoration:underline; </xsl:text>
</xsl:template>
<xsl:template match="@style:text-crossing-out" mode="style">
<xsl:text>text-decoration:line-through; </xsl:text>
</xsl:template>
<xsl:template match="@style:text-blinking" mode="style">
<xsl:text>text-decoration:blink; </xsl:text>
</xsl:template>
<xsl:template match="@style:text-background-color" mode="style">
<xsl:text>background-color:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@style:border-line-width" mode="style">
<xsl:text>border-width:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@style:border-line-width-top" mode="style">
<xsl:text>border-top-width:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@style:border-line-width-bottom" mode="style">
<xsl:text>border-bottom-width:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@style:border-line-width-left" mode="style">
<xsl:text>border-left-width:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="@style:border-line-width-right" mode="style">
<xsl:text>border-right-width:</xsl:text><xsl:value-of select="." /><xsl:text>; </xsl:text>
</xsl:template>
<!-- we need this, otherwise the processor will just print the attribute
contents while we want unmatched attributes not to appear -->
<xsl:template match="@*" mode="style" />
</xsl:stylesheet>
=== Added File zopeproducts/xslt_examples/ooview.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: ooview.py,v 1.1 2003/04/13 16:31:49 faassen Exp $
"""
from zope.publisher.browser import BrowserView
from zope.component import getAdapter
from zope.app.xml.schemainterface import XMLSchemaInterfaceClass
from zope.proxy.introspection import removeAllProxies
class OOView(BrowserView):
def render(self):
xmlsource = getAdapter(
self.context,
XMLSchemaInterfaceClass('http://www.w3.org/hypothetical/html'))
# XXX hack around security weirdness
xmlsource = removeAllProxies(xmlsource)
return xmlsource.source