David:
I use the XSLT taglib to do these things in my content-management site.
> pass the results of one transformation to another (chaining)
simply next xsl taglibs; from my home page:
<!-- news channels -->
<hr />
<xsl:apply xsl="/xsl/recent-links.xsl">
<xsl:apply xsl="/xsl/rdf-to-dl.xsl">
<xsl:apply xsl="/xsl/rss09-to-10.xsl">
<xsl:include page="http://slashdot.org/slashdot.rdf"/>
</xsl:apply>
</xsl:apply>
</xsl:apply>
> have the xml input be a URL instead of a local file name
I tweaked the IncludeTag.java source to do this, but it got over-written
by my last update -- doh! But in short, what you'd do is remove the
lines of code that throw an exception if the page attrib doesn't begin
with '/', and also remove the lines of code that build an explicit URL
from the page attrib. I've attached the hacked source to this email.
Note that with this modification in place, the page attrib MUST be a
fully-qualified, valid URL... not a relative one.
The XSLT stylesheets in the example are at
http://www.aoc.nrao.edu/~bwaters/pub/xsl
and most of them were developed by Eric van der Vlist (http://4xt.org)
Be careful: the xalan XSLT processor can accept stylesheets that attempt
to execute arbitrary java code on your server. So if you accept
stylesheets as URIs, that's maybe a vector for code exploits. (Durn. me
and my big mouth).
Hope this helps,
-- boyd
---------
Boyd Waters [EMAIL PROTECTED]
National Radio Astronomy Observatory http://www.nrao.edu
PO Box 0 Socorro, NM 87801 505.835.7346
http://www.zocalo.net/~waters
[EMAIL PROTECTED]
---------
/*
* $Id: IncludeTag.java,v 1.1 2000/07/03 19:30:03 craigmcc Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", 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 [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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 (INCLUDING, 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.taglibs.xsl;
import java.io.BufferedInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
* Include the contents of the specified page at this point in our output.
* This tag is similar to <code><jsp:include></code>, but does not
* cause the output to be sent directly to the servlet response. Therefore,
* it can be used to capture the content of the page as body content of
* a surrounding tag in which we are nested.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/07/03 19:30:03 $
*/
public class IncludeTag extends TagSupport {
// ------------------------------------------------------------- Properties
/**
* The URI of the page or servlet to be included.
*/
private String page = null;
public String getPage() {
return (this.page);
}
public void setPage(String page) {
this.page = page;
}
// --------------------------------------------------------- Public Methods
/**
* Include the specified page or servlet's output at this point.
*
* @exception JspException if a JSP error occurs
*/
public int doStartTag() throws JspException {
// Set up the output stream to which we will write
JspWriter out = pageContext.getOut();
// Set up a URLConnection to read the requested page. We cannot use
// PageContext.include() because it writes directly to the output
// stream that goes back to the client. :-(
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
StringBuffer url = new StringBuffer();
url.append(page); // FIXME - deal with relative page references
URLConnection conn = null;
try {
conn = (new URL(url.toString())).openConnection();
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(false);
conn.connect();
} catch (Exception e) {
throw new JspException("Error opening connection: " +
e.toString());
}
// Copy the contents of this URL
try {
BufferedInputStream is =
new BufferedInputStream(conn.getInputStream());
InputStreamReader in = new InputStreamReader(is);
while (true) {
int ch = in.read();
if (ch < 0)
break;
out.write(ch);
}
} catch (Exception e) {
throw new JspException("Error reading connection: " +
e.toString());
}
// Skip the body of this tag (which should be empty anyway)
return (SKIP_BODY);
}
}