Re: [xsl] Using the document function with external documents stored in a database

Subject: Re: [xsl] Using the document function with external documents stored in a database
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Mon, 22 Mar 2004 05:49:19 -0800
Bjvrn Boxstart wrote:

Hello all,

I need to perform an XSL-T transformation from Java with Xalan. The challenge is that there are two XML documents involved and that both XML documents are stored in a mysql database. One of the XML documents is the main documents (in the original language). The other document contains a translated version of the source document.

I would like to output a combination of both documents in HTML by using an XSL-T transformation. However I don't want to store the secondary document on the file system of the server before execution of the transformation.

I have two questions:
1. Is it possible to let the document function use a DOM object stored in memory, or an XML document stored in a database?

yes, but you do not need to create a DOM. The best/easiest way would be to use document():


<xsl:apply-templates
  select="document($dbIdentifier)"/>


You need to create (implement) a custom URIResolver like:


public Source resolve(String href, String base) {
  String xmlFromDb = someObj.getXml(href);
  if (xmlFromDb == null) {
    xmlFromDb = "<not-found/>";
  }
  Source source = new StreamSource(new StringReader(xmlFromDb));
/* or
  Source source = new StreamSource(someObj.getXmlAsInputStream(href));
or however...
*/
  return source;
}

best,
-Rob


2. If not... Is it possible to pass a DOM object as a parameter to an XSL-T transformation?

Thanks in advance for your reaction!

Bjvrn

Current Thread