[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: SVNIndexXSLT, server-side processing? [solution]

From: M. van Renswoude <mark_at_x2software.net>
Date: 2004-05-28 13:32:19 CEST

> Try putting
> <xsl:output omit-xml-declaration="yes"/>
> in your xsl file, that should remove the XML PI.

That does the job for the XML declaration, thanks! Unfortunately, IE still
refuses to render it, and I have found out why: the Content-Type header is
text/xml. No Apache directive (such as 'Header') will solve that, so it's
time to hack the SubVersion source. As a note to the authors; I think
server-side XSLT processing is much nicer, and of course much more
compatible with older clients, so here's the suggestion for such a feature

Here's what I did (based on the 1.0.4 source, compiled on Debian Sarge):

- Modify subversion/mod_dav_svn/repos.c, find:

  /* For a directory, we will send text/html or text/xml. If we have a delta
     base, then we will always be generating an svndiff. Otherwise,
     we need to fetch the appropriate MIME type from the resource's
     properties (and use text/plain if it isn't there). */
  if (resource->collection)
      if (resource->info->repos->xslt_uri)
        mimetype = "text/xml";
        mimetype = "text/html; charset=UTF-8";

then comment out the if-else to leave only text/html:

  if (resource->collection)
      /*if (resource->info->repos->xslt_uri)
        mimetype = "text/xml";
        mimetype = "text/html; charset=UTF-8";

Assuming you already have it configured, go through the whole make clean /
make / make install cycle.

Now we need to process the XML output, for this I used xsltproc and a filter
written in Perl. I am planning to write an Apache 2 filter in C one day, but
my knowledge in that area is lacking at the moment so I'll just go for the
quick solution. Works fine for a quiet site.

First, the Perl script. Make sure it's executable by your webserver's user
of course. The source:

use strict;
use Digest::MD5 qw(md5_hex);

my @input = <>;
my $input = join("\n", @input);

# Check for <svn> tag
if ($input =~ /<svn\s/)
  my $file;

  # Let XSLTProc process it
  # I have not found a satisfactory way to call xsltproc without
  # writing a file. Plenty of room for improvements, that's for sure...
    $file = '/tmp/svn_' . md5_hex(localtime());
  } until (!-e $file);

  open (XML, ">$file");
  print XML $input;
  close (XML);

  system("xsltproc $file");
        # Just output it
        print @input;

Now we need to tell Apache to run it, here's my subversion virtual host:

<VirtualHost *:80>
  ExtFilterDefine svnxsl cmd="/web/subversion/xsltransform.pl"

  DAV svn
  SVNParentPath /var/lib/subversion/public
  SVNIndexXSLT "/web/subversion/svnindex.xsl"

  SetOutputFilter svnxsl

I've left out all parts which aren't interesting (ServerName,
authentication, etc). One note here: SVNIndexXSLT is now an absolute path
instead of the old relative path. The reason for this is that xsltproc will
detect the stylesheet reference and apply it, which means we don't have to
provide the location on the command line. Makes it easier to apply different
stylesheets on different hosts...

So far this solution works like a charm.

- Mark

To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri May 28 13:32:44 2004

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.