You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Ryan Davis <ry...@acceleration.net> on 2005/02/11 18:03:42 UTC

Sanity check concerning dynamic XSLT and multiple XML data files

I'm doing my first real cocoon project, and have things working the way I want, but it seems a bit convoluted, and I wanted to just
run it by the folks here to see if I'm missing something obvious.
 
The problem: 
The client wants a folder of xml files, each file representing one member of his staff.  He wants them as separate files so he can
add/edit/delete them easily.  They should all appear on his "staff" page.
 
My solution:
Since I don't know how many XML files, or their names, that seemed to rule out a <map:aggregate>, so the only thing I could think of
was to use a <map:generate type="directory"> to get all the file names in XML, then pass that through an XSLT to produce something
like:
 
<xsl:template match="StaffList">
      <xsl:apply-templates select="document('rel/path/to/staff1.xml')"/>
      <xsl:apply-templates select="document('rel/path/to/staff2.xml')"/>
      <xsl:apply-templates select="document('rel/path/to/staff3.xml')"/>
      <!-- Etc -->
</xsl:template>
 
So, I have one matcher that produces an XSLT like that, and then in my primary matcher, I conditionally add a <map:transform
src="cocoon:/path/to/stafflist.xslt"/> to the pipeline, depending on if I'm serving the staff page.  That way, the staff page
contains a <StaffList> that will get transformed by the dynamic XSLT to contain all the individual staff entries.  
 
I've generalized the process, and am using it for a couple of pages.
 
The only problems I run into are some odd caching behavior where the dynamic XSLT won't regenerate when a file on disk has been
added or removed.  Touching my main site template file invalidates the cache, but I'm guessing there's a better way around that.
 
Does that sound like a reasonable solution?  Is there something simpler that I'm overlooking?
Thanks,
Ryan
----
Ryan Davis
Director of Programming Services
http://www.acceleration.net/