[xslt] xsl:include, xsl:import and catalogs

I have not figured out any way to use a per-stylesheet catalog. 'm not
use it's possible, as it appears as though libxslt will use only the
global catalog.

My particular application is an xslt filter for web servers. Any given
web server may host multiple sites and have multiple DocumentRoots. I
would like to be able to specify an include or import from a href
starting with "http://thissite"; or "me://" or something, and have the
filter add a "me://" -> "http://servername/"; rewrite rule, or similar,
as needed for each individual site. The web server is threaded. If it
were single-process, I could get away with using the global catalog, I
think. With threads, one thread may be processing a request for
servername A, while another is processing a request for servername B,
meaning that if I set a global rewrite rule in the global catalog, it
will probably not do the right thing. Using mutexes will kill
throughput. I can specify full file:// URLs to the documentroot, but
this requires knowing the documentroot for each webserver, and manually
changing it in the include/import statements each time a file is

It looks like I can add a local catalog to a document by using a parser
context and calling xmlCatalogAddLocal (). This looked promising, other
than having to specify a URI (and therefore create and write to disk a
catalog file). However, xsltParseStylesheetDoc () takes an xmlDocPtr,
not a parser context, and the local catalog(s) aren't used. 

I can add a working rule to the global catalog with xmlCatalogAdd(), but
this does not achieve what I need -- a local mapping of some URI prefix
to a different one, such that the webserver's threads won't trample each

>From what I can see, this will require API additions. I hope someone has
a simpler solution.

source snippet:
ctxt = xmlCreateFileParserCtxt("./main.xsl");
sdoc = ctxt->myDoc;
ctxt->catalogs = xmlCatalogAddLocal(ctxt->catalogs,"./catalog.xml");
style = xsltParseStylesheetDoc(sdoc);

<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<rewriteSystem	systemIdStartString = "http://x/"; 
		rewritePrefix = "http://kronk/"/>

<xsl:output method="text"/>
<xsl:include href="http://x/test.xsl"/>
<xsl:template match="test">
This is 'test': <xsl:apply-templates/>

Michael Rothwell
e: rothwell at holly-springs.nc.us
k: http://www.flyingbuttmonkeys.com/rothwell-public-key.txt

This is a digitally signed message part

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]