cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@cocoon.apache.org
Subject [Cocoon Wiki] Updated: DirectoryGenerator
Date Fri, 29 Oct 2004 14:02:23 GMT
   Date: 2004-10-29T07:02:22
   Editor: ViPi <ViPi@arcor.de>
   Wiki: Cocoon Wiki
   Page: DirectoryGenerator
   URL: http://wiki.apache.org/cocoon/DirectoryGenerator

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -19,43 +19,101 @@
 
 This is how you have to define a !DirectoryGenerator (as defined in sitemap.xmap of the cocoon
webapp directory):
 
-{{{
-    <map:generator label="content" 
-                   logger="sitemap.generator.directory" 
-                   name="directory" 
-                   pool-grow="2" pool-max="16" pool-min="2"
-                   src="org.apache.cocoon.generation.DirectoryGenerator"/>
+{{{
+    <map:generator label="content" 
+                   logger="sitemap.generator.directory" 
+                   name="directory" 
+                   pool-grow="2" pool-max="16" pool-min="2"
+                   src="org.apache.cocoon.generation.DirectoryGenerator"/>
 }}}
 
 ===  Usage ===
 
 Example of a simple usage of the !DirectoryGenerator:
 
-{{{
-    <map:match pattern="directory-listing">
-        <map:generate type="directory" src="../directory/to/list/">
-            <map:parameter name="depth" value="2"/>
-        </map:generate>
-        <map:serialize type="xml"/>
-    </map:match>
+{{{
+    <map:match pattern="directory-listing">
+        <map:generate type="directory" src="../directory/to/list/">
+            <map:parameter name="depth" value="2"/>
+        </map:generate>
+        <map:serialize type="xml"/>
+    </map:match>
 }}}
 
 ===  Result ===
 
 This is an example of what you can expect as result of the !DirectoryGenerator.
 
-{{{
-    <dir:directory name="dir1" lastModified="1067545661156" date="30/10/03 21:27" 
-                   size="0" sort="name" reverse="false" requested="true">
-        <dir:directory name="dir11" lastModified="1067295952187" 
-                       date="28/10/03 0:05" size="0"/>
-        <dir:directory name="dir12" lastModified="1067295971203" 
-                       date="28/10/03 0:06" size="0"/>
-        <dir:directory name="dir13" lastModified="1067543010781" 
-                       date="30/10/03 20:43" size="0"/>
-        <dir:directory name="dir14" lastModified="1067545661156" 
-                       date="30/10/03 21:27" size="0"/>
-        <dir:file name="file.xml" lastModified="1067541801328" 
-                       date="30/10/03 20:23" size="79"/>
-    </dir:directory>
+{{{
+    <dir:directory name="dir1" lastModified="1067545661156" date="30/10/03 21:27" 
+                   size="0" sort="name" reverse="false" requested="true">
+        <dir:directory name="dir11" lastModified="1067295952187" 
+                       date="28/10/03 0:05" size="0"/>
+        <dir:directory name="dir12" lastModified="1067295971203" 
+                       date="28/10/03 0:06" size="0"/>
+        <dir:directory name="dir13" lastModified="1067543010781" 
+                       date="30/10/03 20:43" size="0"/>
+        <dir:directory name="dir14" lastModified="1067545661156" 
+                       date="30/10/03 21:27" size="0"/>
+        <dir:file name="file.xml" lastModified="1067541801328" 
+                       date="30/10/03 20:23" size="79"/>
+    </dir:directory>
 }}}
+
+
+===  The Namespace ===
+
+As mentioned in the [http://cocoon.apache.org/2.1/userdocs/generators/directory-generator.html
user documentation], !DirectoryGenerator will generate all elements with the namespace '''http://apache.org/cocoon/directory/2.0''',
so that the afore mentioned example will read like:
+
+{{{
+    <dir:directory name="dir1" lastModified="1067545661156" date="30/10/03 21:27" 
+                   xmlns:dir="http://apache.org/cocoon/directory/2.0
+                   size="0" sort="name" reverse="false" requested="true">
+        <dir:directory name="dir11" lastModified="1067295952187" 
+                       date="28/10/03 0:05" size="0"/>
+        <dir:directory name="dir12" lastModified="1067295971203" 
+                       date="28/10/03 0:06" size="0"/>
+        <dir:directory name="dir13" lastModified="1067543010781" 
+                       date="30/10/03 20:43" size="0"/>
+        <dir:directory name="dir14" lastModified="1067545661156" 
+                       date="30/10/03 21:27" size="0"/>
+        <dir:file name="file.xml" lastModified="1067541801328" 
+                       date="30/10/03 20:23" size="79"/>
+    </dir:directory>
+}}}
+
+Beginners, when converting this kind of output to HTML, sometimes are facing problems on
dealing with this namespace. Matching the elements is one of them and removing that namespace
from the resulting HTML documents is the other. I've even seen some [http://cocoon.apache.org/link/livesites-2.1.html
Cocoon Live Sites] still bearing this namespace within HTML pages, even though (non-X)HTML
standards do not allow any namespace.
+
+The solution is quite easy. The [http://cocoon.apache.org/2.1/userdocs/generators/directory-generator.html
XSLT Standard] says:
+            '''NOTE:''' When a stylesheet uses a namespace declaration only for the purposes
of addressing the source tree, specifying the prefix in the exclude-result-prefixes attribute
will avoid superfluous namespace declarations in the result tree.
+
+As an example, the following stylesheet will transform !DirectoryGenerator's output into
an HTML unordered list with '''no''' such superfluous namespace:
+
+{{{
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+		xmlns:dir="http://apache.org/cocoon/directory/2.0" exclude-result-prefixes="dir"
+		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="dir:directory|dir:file">
+	<li>
+		<xsl:value-of select="@name"/>
+		<xsl:if test="name(.)='dir:directory'">
+			<!-- creating subdirectories -->
+			<ul><xsl:apply-templates/></ul>
+		</xsl:if>
+	</li>
+</xsl:template>
+
+<xsl:template match="/dir:directory">
+	<ul>
+		<xsl:value-of select="@name"/>
+		<!-- creating subdirectories -->
+		<xsl:apply-templates/>
+	</ul>
+</xsl:template>
+
+</xsl:stylesheet>
+}}}
+
+All you need to get rid of the namespace is in line 3.

Mime
View raw message