Subject: Fw: Dynamic stilesheet assignement From: "Benoit Cerrina" <benoit.cerrina@xxxxxxxxxxx> Date: Tue, 17 Oct 2000 21:51:26 +0200 |
Hi, as far as I no, with straight cocoon it is not possible, however since I wanted to do just the same I wrote a new XML producer which you'll find included (you'll have to place it in the src/org/apache/cocoon/producer directory of your cocoon install then rebuild cocoon and declare it as a producer in cocoon.properties) I can now associate dinamically the xsl to the xml using the xslURL parameter of the producer: here is an example form I use for example. <form action="/cocoon/xml/meta.xml"> <input type="hidden" name="producer" value="fileAndXSL"/> <input type="text" name="xslURL" value="../xsl/XMLMeta.xsl"/> <input type="text" name="URL" value="xml/PRODUCT.metadata"/> <input type="submit" value="View Meta"/> </form> Benoit PS to get the class you'll need to copy and paste it since my message with an attachment was bounced ---start java file ProducerFromFileAndXSL.java-------- /*-- $Id: ProducerFromFile.java,v 1.9 2000/05/06 11:13:53 stefano Exp $ -- ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2000 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@xxxxxxxxxxx 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <stefano@xxxxxxxxxx>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.producer; import java.io.*; import java.net.*; import java.util.*; import org.w3c.dom.*; import org.xml.sax.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.cocoon.*; import org.apache.cocoon.framework.*; /** * This class implements the producer interface in order to produce a document * based on its tranlated path. * * @author <a href="mailto:stefano@xxxxxxxxxx">Stefano Mazzocchi</a> * @version $Revision: 1.9 $ $Date: 2000/05/06 11:13:53 $ */ public class ProducerFromFileAndXSL extends AbstractProducer implements Status { private Monitor monitor = new Monitor(10); public Document getDocument(HttpServletRequest request) throws Exception { String file = request.getParameter("URL"); if (file == null) file = Utils.getBasename(request, this.context); this.monitor.watch(Utils.encode(request), new File(file)); //parse the file into a document Document lDoc = parser.parse(new InputSource(file)); //adds a processing instruction with the appropriate xsl if needed ProcessingInstruction lPI = lDoc.createProcessingInstruction("cocoon-process", "type=\"xslt\""); lDoc.appendChild(lPI); String lXslUrl = request.getParameter("xslURL"); if (lXslUrl != null) lPI = lDoc.createProcessingInstruction("xml-stylesheet", "href=\"" + lXslUrl + "\" type=\"text/xsl\""); lDoc.appendChild(lPI); return lDoc; } public Reader getStream(HttpServletRequest request) throws Exception { throw new Exception("this method should never be called!"); } public String getPath(HttpServletRequest request) { return Utils.getBasepath(request, this.context); } public boolean hasChanged(Object context) { return this.monitor.hasChanged(Utils.encode((HttpServletRequest) context)); } public String getStatus() { return "Producer from local file and xsl"; } } ------end java file------------- > ----- Original Message ----- > From: "massimo cravero" <mcravero@xxxxxxxxx> > To: <XSL-List@xxxxxxxxxxxxxxxx> > Sent: Friday, October 13, 2000 6:13 PM > Subject: Dynamic stilesheet assignement > > > > hi. > > > > i'm trying to build a publishing system via the cocoon > > server. > > > > i have a number of XML datasheets and XSL > > stylesheeets: how can i dynamically join them each > > other ? > > in other words, how can i dynamically change the > > assignement > > <?xml-stylesheet type="text/xsl" href="mysheet.xsl"?> > > in the XML file ? > > > > thanks in advance to everyone. > > > > > > > > ===== > > massimo cravero > > mcravero@xxxxxxxxx > > > > > > __________________________________________________ > > Do You Yahoo!? > > Get Yahoo! Mail - Free email you can access from anywhere! > > http://mail.yahoo.com/ > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Dynamic stilesheet assignement, Steve Muench | Thread | xslt assistance please, Azariah Jeyakumar |
White space control when formatting, Rick Anderson | Date | Re: translating between character s, Mike Brown |
Month |