Hi

Upon recommendation from this list, I initially used XPathDirectoryGenerator,
but it was too slow for online use. Since I know when a file is changed, I
call the following URL which produces one large XML file with the contents of
all files in the directory.

A FileChainingGenerator would probably be a better solution, but here I have a
full Cocoon XML/XSLT solution.  Not very elegant, but at least it works. If
somebody comes up with something better, I'll be happy ;-)

Cheers Martin

----
The sitemap entry:

<!-- Update the (cached) list of all files and write it to the file allfiles.xml -->
<map:match pattern="allfiles-update">
  <map:generate type="directory" src="docs">
     <!-- regexp to exclude all files that have characters after ".xml" -->
     <!-- e.g. auto-save files -->
     <map:parameter name="exclude" value=".*\.xml.+"/>
  </map:generate>
  <map:transform src="stylesheets/lib/aggregate.xsl"/>
  <map:transform type="xinclude"/>
  <map:transform src="stylesheets/lib/sourcewrite.xsl">
     <map:parameter name="sourcefile" value="docs/allfiles.xml"/>
  </map:transform>                                                                 
  <map:transform type="write-source"/>
  <map:serialize type="xml"/>
</map:match>       

----
The stylesheet aggregate.xsl (makes list of XLinks)

<?xml version="1.0" encoding="utf-8"?>

<!-- =======================================================================
     Make include tags for all files given in the input (from DirectoryGenerator)
     ======================================================================= -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:dir="http://apache.org/cocoon/directory/2.0"; 
  xmlns:xi="http://www.w3.org/2001/XInclude";
  version="1.0">

  <xsl:output method="xml"/>

  <xsl:template match="/">
    <allglaciers>
      <xsl:apply-templates/>
    </allglaciers>
  </xsl:template>

  <xsl:template match="dir:directory">
    <xsl:for-each select="dir:file">
    <xsl:sort select="@name"/>
    <xi:include parse="xml" href="cocoon:/{../@name}/{@name}#xpointer(/*)" />
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

----
The stylesheet sourcewrite.xsl (makes the sourcewriting tags)

<?xml version="1.0" encoding="utf-8"?>

<!-- =======================================================================
     Make source-writing tags
     ======================================================================= -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

  <xsl:param name="sourcefile"/>
  <xsl:output method="xml"/>

  <xsl:template match="/">
    <source:write xmlns:source="http://apache.org/cocoon/source/1.0";>
      <source:source><xsl:value-of select="$sourcefile"/></source:source>      
      <source:fragment>
        <xsl:copy-of select="*"/>
      </source:fragment>
    </source:write>
  </xsl:template>
</xsl:stylesheet>

----



Jeff Turner <[EMAIL PROTECTED]> writes:

> On Sat, Oct 12, 2002 at 02:08:16PM +0100, Alex McLintock wrote:
> > Hi folks,
> > 
> > I am trying to figure out how to get Cocoon to display all the xml files in 
> > a directory without being explicitly told each of their names in the 
> > sitemap.
> 
> Have a look at the XPathDirectoryGenerator in the scratchpad. With it,
> you can generate a directory listing, with a node extracted from each
> file. Eg, I used it to extract <description> elements from a list of Ant
> scripts:
> 
> http://aft.sourceforge.net/examples/
> 
> The relevant config was:
> 
> <map:sitemap ..
>   <map:components ..
>     <map:generators ..
>       <map:generator  name="xpathdirectory"
>         src="org.apache.cocoon.generation.XPathDirectoryGenerator"/>
> 
>   .....
>   <!-- examples/index.html, listing all scripts -->
>   <map:match pattern="examples/index.xml">
>     <map:generate type="xpathdirectory"
>       src="content/xdocs/examples#/project/description"/>
>     <map:transform
>       src="resources/stylesheets/antdirectory2document.xsl"/>
>     <map:serialize type="xml"/>
>   </map:match>
> 
> 
> --Jeff
> 
> 
> > I guess I need a combination of the Directory Generator and the Aggregation 
> > tools.
> > 
> > I am not too worried about the order of the files otherwise I would have to 
> > use an XML database - which I would like to avoid if possible.
> > 
> > PS I have looked in the Langham/Ziegeler book but can't find anything 
> > useful.
> > 
> > Do I need to write a DirectoryAggregation Generator in Java? perhaps others 
> > would find it useful too.
> > 
> > Alex
> 
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
> For additional commands, e-mail:   <[EMAIL PROTECTED]>
> 
> 

-- 
Martin Lüthi                 [EMAIL PROTECTED]



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to