cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <wallez.anyw...@free.fr>
Subject Re: Viewing XML tags for demo
Date Thu, 07 Sep 2000 08:54:20 GMT


Donald Ball a écrit :
> 
> On Wed, 6 Sep 2000, JAMES VANETTEN wrote:
> 
> > I am putting together a short XML demo page for my intranet developers. I am using
xsp and sql to generate the xml and then applying a stylesheet:
> >
> > <?xml version="1.0"?>
> >
> > <?cocoon-process type="xsp"?>
> > <?cocoon-process type="sql"?>
> > <?cocoon-process type="xslt"?>
> > <?xml-stylesheet href="directory-html.xsl" type="text/xsl"?>
> >
> > I am using the view-source.xml that came with the cocoon demos to
> > allowing viewing of the source xml and xsl page but I also want to be
> > able to view the resulting xml after the sql query and xsp processing.
> > Is there an easy way to do this or do I have to create a stylesheet
> > that simulates this.
> 
> remove the cocoon-process type="xslt" PI. note if you're using xsp, you're
> strongly encouraged to use the sql logicsheet instead of the sql processor
> (or even better, the new esql logicsheet).
> 
> - donald

To achieve the same result without removing <?cocoon-process
type="xslt"?> in all files, I wrote a special debugging XSLT processor
that checks the request for the special "_out" parameter.

Here's the code :
---------------------------------------------------------------------------------
import org.w3c.dom.*;
import org.apache.cocoon.processor.xslt.XSLTProcessor;
import java.util.Dictionary;
import javax.servlet.http.HttpServletRequest;

/**
  A debugging replacement for Cocoon's XSLTProcessor in
cocoon.properties that dumps the input document 
  if the request contains "_out=xml". This allows to know what's
produced by XSP's before XSLT processing.
  @author S. Wallez
  */

public class DebugXSLTProcessor extends XSLTProcessor
{
    public Document process(Document document, Dictionary parameters)
throws Exception
    {
        HttpServletRequest request = (HttpServletRequest)
parameters.get("request");
        if ("xml".equals(request.getParameter("_out")))
        {
            // Remove cocoon and stylesheet PI's
            NodeList list = document.getChildNodes();
            Node node;
            // Backward iteration because removeChilds changes positions
in the list
            for (int i = list.getLength()-1; i >= 0; i--)
            {
                node = list.item(i);
                if (node.getNodeType() ==
Node.PROCESSING_INSTRUCTION_NODE)
                {
                    document.removeChild(node);
                }
            }
            // Add a new PI to dump in XML format.
	   
document.appendChild(document.createProcessingInstruction("cocoon-format",
"type=\"text/xml\""));
            return document;
        }
        else
        {
            // Just do the normal XSLT job
            return super.process(document, parameters);
        }
    }
}    
---------------------------------------------------------------------------------

Now just make this simple change in "cocoon.properties" :
#processor.type.xslt = org.apache.cocoon.processor.xslt.XSLTProcessor
processor.type.xslt = DebugXSLTProcessor

Now type "http://host/my_page.xml?_out=xml" in your browser et voilà (in
french :) you have your XSP result whithout XSL processing.

Hope this helps.

-Sylvain

Mime
View raw message