You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Windler Burri, Sarah" <sa...@id.ethz.ch> on 2003/06/13 14:40:12 UTC
Embed SVG: config example
Hi
because I did not found an example for embed SVG in a HTML file with
Cocoon, I used a lot of time to build the configuration files below. But
now I have it. Maybe the script helps someone else in the same
situation.
Regards
Sarah Windler
<!-- Begin script -->
<!-- sitemap.xmap -->
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<!-- =========================== Components
================================ -->
<map:components>
<map:matchers default="wildcard"/>
<map:transformer logger="sitemap.transformer.extractor"
name="extractor"
src="org.apache.cocoon.transformation.FragmentExtractorTransformer"/>
<map:action logger="sitemap.action.form-validator"
name="form-validator"
src="org.apache.cocoon.acting.FormValidatorAction"/>
<map:generators default="file"/>
<map:transformers default="xslt"/>
<map:readers default="resource"/>
<map:serializers default="html"/>
</map:components>
<!-- ========================= Pipelines
================================= -->
<map:pipelines>
<map:pipeline>
<map:match pattern="">
<map:redirect-to uri="index.html"/>
</map:match>
<map:match pattern="index.html">
<map:act type="form-validator">
<map:parameter name="descriptor" value="docs/form-descriptor.xml"/>
<map:parameter name="validate-set" value="select"/>
<map:generate type="serverpages" src="docs/result.xsp"/>
<map:transform src="stylesheets/svg2html.xsl"/>
<map:transform type="extractor"/>
<map:transform src="stylesheets/fragment-extractor.xsl"/>
<map:serialize/>
</map:act>
<map:generate type="serverpages" src="docs/index.xsp"/>
<map:transform src="stylesheets/index.xsl"/>
<map:serialize/>
</map:match>
<map:match pattern="images/*.svg">
<map:generate type="extractor" src="{1}"/>
<map:serialize/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
<!-- end of sitemap.xmap -->
<!-- index.xsp -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
xmlns:xsp-formval="http://apache.org/xsp/form-validator/2.0">
<document>
<xsp:logic>
String entryString = new String("");
</xsp:logic>
<form handler="index.html">
<row txt="Enter a text:">
<text name="entryString" size="20">
<xsp:attribute name="value">
<xsp:expr>entryString</xsp:expr>
</xsp:attribute>
</text>
</row>
<submit name="Run"/>
</form>
</document>
</xsp:page>
<!-- end of index.xsp -->
<!-- form-descriptor.xml -->
<?xml version="1.0"?>
<root>
<parameter name="entryString" type="string"/>
<constraint-set name="select">
<validate name="entryString" nullable="no"/>
</constraint-set>
</root>
<!-- end of form-descriptor.xml -->
<!-- result.xsp -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
<document>
<xsp:logic>
String entryString = request.getParameter("entryString");
</xsp:logic>
<graph>
<row><xsp:expr>entryString</xsp:expr></row>
</graph>
</document>
</xsp:page>
<!-- end of result.xsp -->
<!-- svg2html.xsl -->
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:import href="template2html.xsl"/>
<xsl:variable name="width" select="600"/>
<xsl:variable name="height" select="200"/>
<xsl:variable name="box-width" select="200"/>
<xsl:variable name="box-height" select="120"/>
<xsl:template match="graph">
<svg:svg width="{$width}" height="{$height}" viewBox="0 0 {$width}
{$height}">
<svg:defs>
<svg:g id="box">
<svg:rect x="0" y="0" width="{$box-width}"
height="{$box-height}"
style="stroke: blue; fill: lightblue;">
</svg:rect>
<svg:text style="stroke-opacity:0.25;"
x="{ $box-width div 2}"
y="{$box-height div 2}"><xsl:value-of select="."/>
<animate attributeName="x" from="0" to="{
$box-width -70}"
dur="10s"
repeatCount="indefinite"/>
</svg:text>
</svg:g>
</svg:defs>
<svg:use xlink:href="#box" x="100" y="50"/>
</svg:svg>
</xsl:template>
</xsl:stylesheet>
<!-- end of svg2html.xsl -->
<!-- fragment-extractor.xsl -->
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fe="http://apache.org/cocoon/fragmentextractor/2.0">
<xsl:template match="//fe:fragment">
<embed src="images/{@fragment-id}.svg" name="SVGEmbed" width="600"
height="200"
type="image/svg+xml"
pluginspage="http::/www.adobe.com/svg/viewer/install/"/>
</xsl:template>
<xsl:template match="@*|*|text()|processing-instruction()"
priority="-1">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<!-- end of fragmen-extractor.xsl -->
<!-- index.xsl -->
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform> ">
<xsl:import href="template2html.xsl"/>
<xsl:template match="form">
<form name="form_{@name <ma...@name> }" action="{@handler
<ma...@handler> }" method="POST">
<xsl:apply-templates/>
</form>
</xsl:template>
<xsl:template match="row">
<p><xsl:value-of select="@txt"/><br /><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="submit">
<input type="submit" name="cocoon-action-{@name
<ma...@name> }" value="{@name}"/ <mailto:{@name}"/> >
</xsl:template>
<xsl:template match="text">
<input type="text" name="{@name <ma...@name> }" size="{@size
<ma...@size> }">
<xsl:attribute name="value">
<xsl:value-of select="normalize-space(@value)"/>
</xsl:attribute>
</input>
</xsl:template>
</xsl:stylesheet>
<!-- end of index.xsl -->
<!-- template2html.xsl -->
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform> ">
<xsl:template match="/">
<html>
<head>
<title>Embed SVG</title>
</head>
<body bgcolor="#ffffff">
<h2>Embed SVG in HTML</h2>
<p><xsl:apply-templates/></p>
<hr></hr>
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td align="left"><font
face="arial,helvetica,sanserif" size="-1"><i>
Revised: 13. Juni 2003 (sw)</i></font></td>
<td align="right"><font
face="arial,helvetica,sanserif" size="-1"><i>
Build with <a href="Cocoon
<http://xml.apache.org/cocoon/index.html">
http://xml.apache.org/cocoon/index.html">Cocoon</a>.
</i></font>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<!-- end of template2html.xsl -->
<!-- End of script -->