Author: bdelacretaz
Date: Fri Apr 22 03:56:15 2005
New Revision: 164215

URL: http://svn.apache.org/viewcvs?rev=164215&view=rev
Log:
sync html block samples with 2.x branch (new HTMLTransformer sample)

Added:
    cocoon/blocks/supported/html/trunk/conf/html-transformer.xmap
    cocoon/blocks/supported/html/trunk/samples/htmltransformer/
    cocoon/blocks/supported/html/trunk/samples/htmltransformer/input.xml
    
cocoon/blocks/supported/html/trunk/samples/htmltransformer/post-transformer-filter.xsl
Modified:
    cocoon/blocks/supported/html/trunk/samples/samples.xml
    cocoon/blocks/supported/html/trunk/samples/sitemap.xmap

Added: cocoon/blocks/supported/html/trunk/conf/html-transformer.xmap
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/supported/html/trunk/conf/html-transformer.xmap?rev=164215&view=auto
==============================================================================
--- cocoon/blocks/supported/html/trunk/conf/html-transformer.xmap (added)
+++ cocoon/blocks/supported/html/trunk/conf/html-transformer.xmap Fri Apr 22 
03:56:15 2005
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- CVS $Id: samples.xml 158439 2005-03-21 10:17:23Z cziegeler $ -->
+
+<xmap xpath="/sitemap/components/transformers" unless="[EMAIL 
PROTECTED]'html']">
+    <map:transformer
+      name="html"
+      logger="sitemap.transformer.html"
+      src="org.apache.cocoon.transformation.HTMLTransformer"
+    />
+</xmap>

Added: cocoon/blocks/supported/html/trunk/samples/htmltransformer/input.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/supported/html/trunk/samples/htmltransformer/input.xml?rev=164215&view=auto
==============================================================================
--- cocoon/blocks/supported/html/trunk/samples/htmltransformer/input.xml (added)
+++ cocoon/blocks/supported/html/trunk/samples/htmltransformer/input.xml Fri 
Apr 22 03:56:15 2005
@@ -0,0 +1,82 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- CVS $Id: samples.xml 158439 2005-03-21 10:17:23Z cziegeler $ -->
+
+<html-transformer-test>
+  <div id="explain">
+    <p>
+      This XML file contains HTML code with escaped markup: tags are written
+      like &amp;lt;body/&amp;gt; with escaped &lt; and &gt; signs. This is
+      often the case with RSS feeds.
+    </p>
+    <p>
+      In this example, the HTMLTransformer is configured to parse the contents
+      of the &lt;description&gt; and &lt;escaped-html&gt;, elements, creating
+      well-formed content from this escaped markup.
+    </p>
+    <p>
+      A downstream transform is used to filter the result, as the 
HTMLTransformer
+      writes full HTML documents as &lt;html&gt; elements, for each input 
element
+      that it parses.
+    </p>
+    <p>
+      For more info search "HTMLTransformer" in the sitemap that drives this 
sample.
+    </p>
+  </div>
+  <div id="content-with-escaped-html">
+    <div id="example-1">
+      <description>
+        <!-- this element does not contain markup, only text with escaped &lt; 
and &gt; signs -->
+        &lt;div style="background: #FFFFCC; color: black; margin: 1em;"&gt;
+        &lt;h1&gt;Here's some escaped HTML&lt;/h1&gt;
+        This test document contains escaped HTML code in the description 
elements,
+        as is customary in RSS documents for example.
+        &lt;p&gt;
+
+        &lt;img align="right" 
src="http://cocoon.apache.org/2.1/images/cocoon.gif"/&gt;
+
+        This description element contains escaped html markup, which should be
+        converted to proper html by the HTMLTransformer. If the Cocoon logo is 
shown
+        properly, it means that the parsing worked.
+        &lt;blockquote&gt;
+        This should be a blockquote and &lt;b&gt;here's some bold&lt;/b&gt;.
+        &lt;/blockquote&gt;
+        Note that the HTMLTransformer generates a complete HTML document for 
each element that
+        is parsed - here this is filtered downstream to keep only the contents 
of the &amp;lt;body&amp;gt;
+        of the parsed documents.
+        &lt;/div&gt;
+      </description>
+    </div>
+
+    <div id="example-2">
+      <escaped-html>
+        &lt;div style="background: #FFFFCC; color: black; margin: 1em;"&gt;
+        &lt;h1&gt;More escaped HTML&lt;/h1&gt;
+
+         &lt;img align="right" 
src="http://cocoon.apache.org/2.1/images/cocoon.gif"/&gt;
+
+         Another description element with escaped html markup, including a 
Cocoon logo.
+         &lt;p&gt;
+         Here's some &lt;i&gt;italic&lt;/i&gt; and a &lt;a 
href="http://cocoon.apache.org"&gt;
+         link to the Cocoon site&lt;/a&gt;.
+
+         &lt;/div&gt;
+      </escaped-html>
+    </div>
+  </div>
+</html-transformer-test>
\ No newline at end of file

Added: 
cocoon/blocks/supported/html/trunk/samples/htmltransformer/post-transformer-filter.xsl
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/supported/html/trunk/samples/htmltransformer/post-transformer-filter.xsl?rev=164215&view=auto
==============================================================================
--- 
cocoon/blocks/supported/html/trunk/samples/htmltransformer/post-transformer-filter.xsl
 (added)
+++ 
cocoon/blocks/supported/html/trunk/samples/htmltransformer/post-transformer-filter.xsl
 Fri Apr 22 03:56:15 2005
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--
+  Filter the output of the HTMLTransformer
+  
+  CVS $Id: samples.xml 158439 2005-03-21 10:17:23Z cziegeler $
+-->
+
+<xsl:transform
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+>
+
+  <xsl:param name="title" select="'HTMLTransformer output'"/>
+
+  <!-- convert to an html document -->
+  <xsl:template match="/">
+    <html>
+      <head>
+        <style type="text/css">
+          .note { font-size: 80%; font-style=italic; }
+          .parsedHtml { margin: 1em; border: solid gray 1px; }
+        </style>
+        <title><xsl:value-of select="$title"/></title>
+      </head>
+      <body>
+        <h1><xsl:value-of select="$title"/></h1>
+        <xsl:apply-templates/>
+      </body>
+    </html>
+  </xsl:template>
+
+  <!--
+    The HTMLTransformer produces html elements inside the document,
+    keep the contents of their body only
+  -->
+  <xsl:template match="*/html">
+    <div class="parsedHtml">
+      <p class="note">This was parsed by the HTMLTransformer:</p>
+      <xsl:apply-templates select="body/node()"/>
+    </div>
+  </xsl:template>
+
+  <!-- by default copy everything -->
+  <xsl:template match="*" priority="-1">
+    <xsl:copy>
+      <xsl:copy-of select="@*"/>
+      <xsl:apply-templates/>
+    </xsl:copy>
+  </xsl:template>
+
+</xsl:transform>
\ No newline at end of file

Modified: cocoon/blocks/supported/html/trunk/samples/samples.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/supported/html/trunk/samples/samples.xml?rev=164215&r1=164214&r2=164215&view=diff
==============================================================================
--- cocoon/blocks/supported/html/trunk/samples/samples.xml (original)
+++ cocoon/blocks/supported/html/trunk/samples/samples.xml Fri Apr 22 03:56:15 
2005
@@ -29,4 +29,16 @@
       Shows how to get remote resource and convert it to valid XHTML using 
HTMLGenerator.
     </sample>
   </group>
+
+  <group name="HTMLTransformer">
+    <sample name="XML input" href="HTMLTransformer/input.xml">
+      XML document containing escaped HTML, blocks of HTML code written
+      as strings inside elements (as often found in RSS feeds)
+    </sample>
+    <sample name="Parsed output" href="HTMLTransformer/parsed.xml">
+      HTMLTransformer applied to input.xml: escaped
+      HTML markup is converted to XHTML
+    </sample>
+  </group>
+
 </samples>

Modified: cocoon/blocks/supported/html/trunk/samples/sitemap.xmap
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/supported/html/trunk/samples/sitemap.xmap?rev=164215&r1=164214&r2=164215&view=diff
==============================================================================
--- cocoon/blocks/supported/html/trunk/samples/sitemap.xmap (original)
+++ cocoon/blocks/supported/html/trunk/samples/sitemap.xmap Fri Apr 22 03:56:15 
2005
@@ -67,6 +67,22 @@
         <map:serialize type="xhtml"/>
       </map:match>
 
+      <!-- ================  HTMLTransformer ================= -->
+
+      <map:match pattern="HTMLTransformer/input.xml">
+        <map:generate src="htmltransformer/input.xml"/>
+        <map:serialize type="xml"/>
+      </map:match>
+
+      <map:match pattern="HTMLTransformer/parsed.xml">
+        <map:generate src="htmltransformer/input.xml"/>
+        <map:transform type="html">
+          <map:parameter name="tags" value="description,escaped-html"/>
+        </map:transform>
+        <map:transform src="htmltransformer/post-transformer-filter.xsl"/>
+        <map:serialize type="xhtml"/>
+      </map:match>
+
     </map:pipeline>
   </map:pipelines>
 </map:sitemap>


Reply via email to