Project

Profile

Help

xsl:result-document as string and not as file

Added by Anonymous over 17 years ago

Legacy ID: #4468040 Legacy Poster: Marco Pehla (marco_pehla)

Hello everybody, I use Saxon 8 inside of a EJB3 on the JBoss application server and need to create multiple outputs of a single XSLT transformation. Therefore I tired to use the xsl:result-document element. <xsl:result-document href="file1.txt"> <xsl:text>content 01</xsl:text> </xsl:result-document> <xsl:result-document href="file2.txt"> <xsl:text>content 02</xsl:text> </xsl:result-document> Since file creation / access is forbidden inside of a EJB container, how could I create a set/array or another kind of object instead of files? I guess there must be a solution. I search, but did not found anything. with kind regards, Marco


Replies (2)

RE: xsl:result-document as string and not as - Added by Anonymous over 17 years ago

Legacy ID: #4468096 Legacy Poster: Michael Kay (mhkay)

You can register an OutputURIResolver to handle the result documents. This can nominate any JAXP Result object to recieve the output, for example a StreamResult which can wrap a StringWriter.

RE: xsl:result-document as string and not as - Added by Anonymous over 17 years ago

Legacy ID: #4468583 Legacy Poster: Marco Pehla (marco_pehla)

THANK YOU VERY MUCH MICHAEL!!! Now I can drop my dirty >>seperation of classes that are in a single string<< solution. ;) The keyword was OutputURIResolver . In the following an example solution. In the class that use Saxon you need to include this lines: transformerFactory.setAttribute("http://saxon.sf.net/feature/outputURIResolver", new MemoryOutputURIResolver()); transformerFactory.setAttribute("http://saxon.sf.net/feature/allow-external-functions", new Boolean(true)); This comes into a new class MemoryOutputURIResolver.java : import javax.xml.transform.; import javax.xml.transform.stream.; import net.sf.saxon.*; public class MemoryOutputURIResolver implements OutputURIResolver { public Result resolve(String href, String base) throws TransformerException { if (href.endsWith(".out")) { System.out.println("** Start " + href + " "); StreamResult res = new StreamResult(System.out); res.setSystemId(href); return res; } else { return null; } } public void close(Result result) throws TransformerException { System.out.println(" End " + result.getSystemId() + " **"); } }

    (1-2/2)

    Please register to reply