You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@forrest.apache.org by Vassilis Koutavas <va...@gmail.com> on 2007/03/03 21:32:42 UTC

Generating an aggregated xml from all the files in a directory

What is the right way to create one aggregated xml file from all the
xml files in a directory?
I think I need to use map:aggregate, map:part, and dir:directory in my
sitemap.xml, but I don't quite understand how to put them together. I
don't know how many files will be in the directory, thus I don't know
how many parts the aggregation will have.

Let's say that in my xdocs I have the directory called "the/dir/" in
which there are a number of xml files, and I want to create a file
called "the-list.xml" (in the same direcory) which will contain the
contents of all the xml files in that directory, under a common
element called "elements". After I have this I know how to transform
it using an xsl, and produce the final html file.

Best
-- 
Vassilis

Re: Generating an aggregated xml from all the files in a directory

Posted by Ross Gardler <rg...@apache.org>.
Vassilis Koutavas wrote:
> Thank you both very much! I would've never discovered how this works by 
> myself.

Glad you got it working.

It would be really helpful if you could put your new found skills into a 
  entry for our FAQ, or if you have a little more time perhaps a How-To.

> I still don't understand which is the root element of the
> aggregation and I don't know how to debug in forrest to find out. I
> just matched the root element with "/" in the xsl.

When it comes to understanding the Cocoon components, the best resource 
is the Cocoon docs. So for the directory generator you have [1] and for 
the XPath generatpr [2]

> I also added the above in the sitemap.xmap, instead of the input.xml,
> because I don't find any reason why the input.xmap file needs to
> exist. Maybe it has a reason if you speak about seperate modules and
> plugins, but none for a single project.

Yes, I pointed you to an example in a plugin, but you opted to put it in 
to your project sitemap. This is perfectly OK if the work is only 
appropriate to that particular project. Otherwise you would want to put 
it in a plugin [3]

> Another point in the resume example that I had to change is the value
> of the "src" field of the xpathdirectory generator from
> 
> {property:content.xdocs}{1}buildings
> 
> to
> 
> {project:content.xdocs}{1}buildings

Yes, I should have thought to mention that. The Resume plugin is written 
for 0.8-dev, but you appear to be using 0.7.

> Thanks again for your help, and I wish in the future there will be a
> *real* reference document for forrest and cocoon. (See Java's API
> reference to see how I think it should look like.)

I think if you look at the links I provide below that all the low level 
documentation is available. What is missing is a nice clear description 
of how to use this in a specific use case, like yours. It has come up 
before on this list, so this documentation also exists in the list 
archives (and thanks to your follow up here it is now even clearer in 
the archives)

We welcome any further contribution to our docs.

Ross

[1] http://cocoon.apache.org/2.1/userdocs/directory-generator.html
[2] http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html
[3] http://forrest.apache.org/docs_0_70/howto/howto-buildPlugin.html

Re: Generating an aggregated xml from all the files in a directory

Posted by Vassilis Koutavas <va...@gmail.com>.
Thank you both very much! I would've never discovered how this works by myself.

As it turned out I had to do a combination of both your answers and a
liitle experimentation to make things work. For future reference
here's what I had to do:

Add in sitemap.xmap  *two* things:
  (a) a new generator componet:

  <map:components>
    <map:generators>
      <map:generator name="sxw" label="content" logger="sitemap.generator.sxw"
        src="org.apache.forrest.generation.SXWGenerator"/>
      <map:generator name="xpathdirectory"
src="org.apache.cocoon.generation.XPathDirectoryGenerator" />
      <map:generator name="directory"
src="org.apache.cocoon.generation.DirectoryGenerator"/>
    </map:generators>
  ...

 (b) A new match-pattern (how are these things called anyway?) in the
standard pipeline.

    <map:match pattern="**buildings/building-table.xml">
      <map:generate type="xpathdirectory"
                    src="{project:content.xdocs}{1}buildings">
        <map:parameter name="xpath" value="/building"/>
        <map:parameter name="include" value="\.*-bld.xml$"/>
      </map:generate>
      <map:transform
src="{project:resources.stylesheets}/buildingtable2document.xsl" />
      <map:serialize type="xml"/>
    </map:match>

  Here I used the xpathdirectory, proposed by Evangelos, because the
directory generator used in the resume example was not selecting any
node. I still don't understand which is the root element of the
aggregation and I don't know how to debug in forrest to find out. I
just matched the root element with "/" in the xsl.

I also added the above in the sitemap.xmap, instead of the input.xml,
because I don't find any reason why the input.xmap file needs to
exist. Maybe it has a reason if you speak about seperate modules and
plugins, but none for a single project.

Another point in the resume example that I had to change is the value
of the "src" field of the xpathdirectory generator from

{property:content.xdocs}{1}buildings

to

{project:content.xdocs}{1}buildings

I think the resume example needs to be corrected there, unless there
is something different in the cvs version of forrest.

Thanks again for your help, and I wish in the future there will be a
*real* reference document for forrest and cocoon. (See Java's API
reference to see how I think it should look like.)

--Vassilis



On 3/3/07, Ross Gardler <rg...@apache.org> wrote:
> Ross Gardler wrote:
> > Vassilis Koutavas wrote:
> >> What is the right way to create one aggregated xml file from all the
> >> xml files in a directory?
> >
> > Take a look at the resume input plugin in the whiteboard in SVN head [1]
>
> Sorry forgot the URL
>
> [1]
> http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.input.Resume/input.xmap?revision=431247&view=markup
>
> Ross
>


-- 
Vassilis

Re: Generating an aggregated xml from all the files in a directory

Posted by Ross Gardler <rg...@apache.org>.
Ross Gardler wrote:
> Vassilis Koutavas wrote:
>> What is the right way to create one aggregated xml file from all the
>> xml files in a directory?
> 
> Take a look at the resume input plugin in the whiteboard in SVN head [1]

Sorry forgot the URL

[1] 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.input.Resume/input.xmap?revision=431247&view=markup

Ross

Re: Generating an aggregated xml from all the files in a directory

Posted by Ross Gardler <rg...@apache.org>.
Vassilis Koutavas wrote:
> What is the right way to create one aggregated xml file from all the
> xml files in a directory?

Take a look at the resume input plugin in the whiteboard in SVN head [1]

In particular:

       <map:match pattern="team/all.source.xml">
         <map:generate type="directory" 
src="{properties:content.xdocs}/team/resume">
           <map:parameter name="include" value=".*.xml$"/>
         </map:generate>
         <map:transform src="resources/stylesheets/directory2resumes.xsl"/>
         <map:transform type="cinclude"/>
         <map:serialize type="xml"/>
       </map:match>

This uses CInclude to create the aggregate document, this utilises 
Cocoons caching to its fullest extent. It can be done with xinclude, but 
Cocoon can't cache this since the inclusion is done in the XSLT parser. 
You could also do it with the XSLT document() function, but again this 
means Cocoon can't cache it.

Ross

Re: Generating an aggregated xml from all the files in a directory

Posted by Evangelos Vlachogiannis <ev...@aegean.gr>.
Hi Vasili,

lets say you have n xml files in a dir with root elements 
<article></article>

<map:generate type="xpathdirectory" src="the/requested/directory">
    <map:parameter name="xpath" value="/article"/>
    <map:parameter name="xmlFiles" value="\.x.*$"/>
  </map:generate>

this will return something like:

<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
    name="articles" lastModified="1057183738609" date="03.07.03 00:08" size="0"
    requested="true" sort="name" reverse="false">
  <dir:file name="article1.xml" lastModified="1057183738609" date="03.07.03 00:08" size="123">
    <dir:xpath query="/article">
      <article>My first article - whole xml!</article>
    </dir:xpath>
  </dir:file>
  <dir:file name="article2.xml" lastModified="1057183738609" date="03.07.03 00:08" size="123">
    <dir:xpath query="/article">
      <article>My second article - whole xml!</article>
    </dir:xpath>
  </dir:file>
</dir:directory>

Then you can play with 1 or more xslt files and get the serialization 
you need.

But remember you need to check if this generator is included in 
forrest... I do not know... I have used that with cocoon, no with 
forrest...

Vangelis

Vassilis Koutavas wrote:
> Thanks Vangeli,
>
> So let me get this straight. Can I write:
>
> <dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
>    name="the/dir/" sort="name" reverse="false">
>  <dir:file name="*.xml">
>    <dir:xpath query="*"/>
>  </dir:file>
> </dir:directory>
>
> to get all the contents of all files in the/directory? (I'm sorry but
> I'm ignorant about xpath)
>
> Then the question is how do I put this in a forrest's aggregation. Or
> I don't need an aggregation if I use this?
>
> --Vassilis
>
> On 3/3/07, Evangelos Vlachogiannis <ev...@aegean.gr> wrote:
>> Hi Vasili,
>>
>> I think you need Xpathdirectory Generator
>> (http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html). I
>> hope this is included in forrest..
>> Then you just have a root element (elements) and call an xpath
>> expression to include what ever elements you need from xmls in dir.
>>
>> hope that helps,
>> Vangelis
>>
>> Vassilis Koutavas wrote:
>> > What is the right way to create one aggregated xml file from all the
>> > xml files in a directory?
>> > I think I need to use map:aggregate, map:part, and dir:directory in my
>> > sitemap.xml, but I don't quite understand how to put them together. I
>> > don't know how many files will be in the directory, thus I don't know
>> > how many parts the aggregation will have.
>> >
>> > Let's say that in my xdocs I have the directory called "the/dir/" in
>> > which there are a number of xml files, and I want to create a file
>> > called "the-list.xml" (in the same direcory) which will contain the
>> > contents of all the xml files in that directory, under a common
>> > element called "elements". After I have this I know how to transform
>> > it using an xsl, and produce the final html file.
>> >
>> > Best
>>
>> -- 
>> ---------------------------------------------------------------
>> Evangelos Vlachogiannis
>> Researcher - PhD. Candidate
>> Contact: http://www.syros.aegean.gr/users/evlach/contactme.php
>> ---------------------------------------------------------------
>>
>>
>
>

-- 
---------------------------------------------------------------
Evangelos Vlachogiannis
Researcher - PhD. Candidate
Contact: http://www.syros.aegean.gr/users/evlach/contactme.php
--------------------------------------------------------------- 


Re: Generating an aggregated xml from all the files in a directory

Posted by Vassilis Koutavas <va...@gmail.com>.
Thanks Vangeli,

So let me get this straight. Can I write:

<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
    name="the/dir/" sort="name" reverse="false">
  <dir:file name="*.xml">
    <dir:xpath query="*"/>
  </dir:file>
</dir:directory>

to get all the contents of all files in the/directory? (I'm sorry but
I'm ignorant about xpath)

Then the question is how do I put this in a forrest's aggregation. Or
I don't need an aggregation if I use this?

--Vassilis

On 3/3/07, Evangelos Vlachogiannis <ev...@aegean.gr> wrote:
> Hi Vasili,
>
> I think you need Xpathdirectory Generator
> (http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html). I
> hope this is included in forrest..
> Then you just have a root element (elements) and call an xpath
> expression to include what ever elements you need from xmls in dir.
>
> hope that helps,
> Vangelis
>
> Vassilis Koutavas wrote:
> > What is the right way to create one aggregated xml file from all the
> > xml files in a directory?
> > I think I need to use map:aggregate, map:part, and dir:directory in my
> > sitemap.xml, but I don't quite understand how to put them together. I
> > don't know how many files will be in the directory, thus I don't know
> > how many parts the aggregation will have.
> >
> > Let's say that in my xdocs I have the directory called "the/dir/" in
> > which there are a number of xml files, and I want to create a file
> > called "the-list.xml" (in the same direcory) which will contain the
> > contents of all the xml files in that directory, under a common
> > element called "elements". After I have this I know how to transform
> > it using an xsl, and produce the final html file.
> >
> > Best
>
> --
> ---------------------------------------------------------------
> Evangelos Vlachogiannis
> Researcher - PhD. Candidate
> Contact: http://www.syros.aegean.gr/users/evlach/contactme.php
> ---------------------------------------------------------------
>
>


-- 
Vassilis

Re: Generating an aggregated xml from all the files in a directory

Posted by Evangelos Vlachogiannis <ev...@aegean.gr>.
Hi Vasili,

I think you need Xpathdirectory Generator 
(http://cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html). I 
hope this is included in forrest..
Then you just have a root element (elements) and call an xpath 
expression to include what ever elements you need from xmls in dir.

hope that helps,
Vangelis

Vassilis Koutavas wrote:
> What is the right way to create one aggregated xml file from all the
> xml files in a directory?
> I think I need to use map:aggregate, map:part, and dir:directory in my
> sitemap.xml, but I don't quite understand how to put them together. I
> don't know how many files will be in the directory, thus I don't know
> how many parts the aggregation will have.
>
> Let's say that in my xdocs I have the directory called "the/dir/" in
> which there are a number of xml files, and I want to create a file
> called "the-list.xml" (in the same direcory) which will contain the
> contents of all the xml files in that directory, under a common
> element called "elements". After I have this I know how to transform
> it using an xsl, and produce the final html file.
>
> Best

-- 
---------------------------------------------------------------
Evangelos Vlachogiannis
Researcher - PhD. Candidate
Contact: http://www.syros.aegean.gr/users/evlach/contactme.php
---------------------------------------------------------------