logo       

[Cocoon Wiki] Updated: DirectoryGenerator: msg#00275

Subject: [Cocoon Wiki] Updated: DirectoryGenerator
   Date: 2004-10-29T07:02:22
   Editor: ViPi <ViPi@xxxxxxxx>
   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.



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    politics.lenini...    audio.emagic.ex...    tex.texinfo.gen...    handhelds.linux...    ietf.sipping/20...    lang.erlang.gen...    cygwin.talk/200...    yellowdog.gener...    mozilla.devel.l...    xfree86.newbie/...    openbsd.ports/2...    db.oracle.devel...    kde.kalyxo.deve...    user-groups.lin...    bbc.cvs/2003-04...    gnu.libtool.bug...    redhat.k12osn/2...    emulators.wine....    freebsd.devel.d...    search.xapian.g...    java.izpack.use...    network.mrtg.us...    windows.total-c...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe