cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neeme Praks" <ne...@one.lv>
Subject RE: recursive func in XSP?
Date Tue, 06 Jun 2000 13:02:16 GMT

Ok, solved this "mysterious" problem. My own stupidity, I had two
<xsl:template match="portlet"> (portlet is the root element) sections,
and only the last one got processed. So there was no root element in the
resulting document.

Neeme

> -----Original Message-----
> From: Neeme Praks 
> Sent: Monday, June 05, 2000 3:40 PM
> To: cocoon-dev@xml.apache.org
> Subject: RE: recursive func in XSP?
> 
> 
> 
> OK, now I got it working to some extent...
> 
> However I get some mysterious error messages (well, mysterious for me,
> at least) when I try to add some text to the rootelement:
> 
> org.apache.xalan.xslt.XSLProcessorException: Warning: can't 
> output text
> before document element!  Ignoring...
> 	at
> org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1630)
> 	at
> org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1594)
> 	at
> org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java,
> Compiled Code)
> 	at
> org.apache.cocoon.transformer.XalanTransformer.transform(Xalan
> Transforme
> r.java, Compiled Code)
> 	at
> org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTPro
> cessor.jav
> a:110)
> 	at org.apache.cocoon.Engine.handle(Engine.java, Compiled Code)
> 	at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
> 	at
> org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWra
> pper.java,
> Compiled Code)
> 	at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:523)
> 	at
> org.apache.tomcat.service.http.HttpConnectionHandler.processCo
> nnection(H
> ttpConnectionHandler.java:146)
> 	at
> org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEnd
> point.java
> :334)
> 	at java.lang.Thread.run(Thread.java:479)
> ---------
> org.xml.sax.SAXException: Warning: can't output text before document
> element!  Ignoring...
> 	at
> org.apache.xalan.xpath.xml.FormatterToDOM.append(FormatterToDOM.java,
> Compiled Code)
> 	at
> org.apache.xalan.xpath.xml.FormatterToDOM.characters(Formatter
> ToDOM.java
> , Compiled Code)
> 	at
> org.apache.xalan.xslt.XSLTEngineImpl$ResultTreeHandler.charact
> ers(XSLTEn
> gineImpl.java, Compiled Code)
> 	at
> org.apache.xalan.xslt.XSLTEngineImpl.cloneToResultTree(XSLTEng
> ineImpl.ja
> va:1998)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemT
> emplateEle
> ment.java:1172)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(E
> lemTemplat
> eElement.java:1056)
> 	at
> org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNo
> deLocator.
> java, Compiled Code)
> 	at
> org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java,
> Compiled Code)
> 	at
> org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNo
> deLocator.
> java:296)
> 	at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
> 	at org.apache.xalan.xpath.XPath.execute(XPath.java, Compiled
> Code)
> 	at org.apache.xalan.xpath.XPath.execute(XPath.java, Compiled
> Code)
> 	at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChi
> ldren(Elem
> TemplateElement.java, Compiled Code)
> 	at
> org.apache.xalan.xslt.ElemApplyTemplates.execute(ElemApplyTemp
> lates.java
> :176)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.executeChildren(Elem
> TemplateEl
> ement.java, Compiled Code)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemT
> emplateEle
> ment.java:1194)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(E
> lemTemplat
> eElement.java:1056)
> 	at
> org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNo
> deLocator.
> java, Compiled Code)
> 	at
> org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java,
> Compiled Code)
> 	at
> org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNo
> deLocator.
> java:296)
> 	at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
> 	at org.apache.xalan.xpath.XPath.execute(XPath.java, Compiled
> Code)
> 	at org.apache.xalan.xpath.XPath.execute(XPath.java, Compiled
> Code)
> 	at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChi
> ldren(Elem
> TemplateElement.java, Compiled Code)
> 	at
> org.apache.xalan.xslt.ElemApplyTemplates.execute(ElemApplyTemp
> lates.java
> :176)
> 	at
> org.apache.xalan.xslt.ElemTemplateElement.executeChildren(Elem
> TemplateEl
> ement.java, Compiled Code)
> 	at
> org.apache.xalan.xslt.ElemTemplate.execute(ElemTemplate.java:145)
> 	at
> org.apache.xalan.xslt.StylesheetRoot.process(StylesheetRoot.java,
> Compiled Code)
> 	at
> org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java,
> Compiled Code)
> 	at
> org.apache.cocoon.transformer.XalanTransformer.transform(Xalan
> Transforme
> r.java, Compiled Code)
> 	at
> org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTPro
> cessor.jav
> a:110)
> 	at org.apache.cocoon.Engine.handle(Engine.java, Compiled Code)
> 	at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
> 	at
> org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWra
> pper.java,
> Compiled Code)
> 	at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:523)
> 	at
> org.apache.tomcat.service.http.HttpConnectionHandler.processCo
> nnection(H
> ttpConnectionHandler.java:146)
> 	at
> org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEnd
> point.java
> :334)
> 	at java.lang.Thread.run(Thread.java:479)
> 
> I have the following XSP page:
> <?xml version="1.0"?>
> <?cocoon-process type="xslt"?>
> <?xml-stylesheet href="one-xsp.xsl" type="text/xsl"?>
> <portlet xmlns:one="http://www.one.lv/Utils">
> Your folders:
> 	<FolderTree UserID="1" SelectedID="0" RemovedID="0"/>
> </portlet>
> 
> It works fine if I remove the "Your folders:" part, like this:
> <?xml version="1.0"?>
> <?cocoon-process type="xslt"?>
> <?xml-stylesheet href="one-xsp.xsl" type="text/xsl"?>
> <portlet xmlns:one="http://www.one.lv/Utils">
> 	<FolderTree UserID="1" SelectedID="0" RemovedID="0"/>
> </portlet>
> 
> Also, the XML get's generated nicely, if I remove the XML->HTML
> stylesheet, I get the following output:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
> "http://www.w3.org/TR/REC-html40/strict.dtd">
> <portlet>
> Your folders:
> 	<FolderTree><folder id="263"><name>neeme@one.lv</name><folder
> id="269"><name>Alerts</name><folder id="471"><name>hoho</name><folder
> id="474"><name>kalasaba</name></folder><folder
> id="472"><name>huhu</name><description>kfjkdkdfjkfj</descripti
> on></folde
> r></folder><folder
> id="473"><name>hohu444</name><description>kalamees</descriptio
> n></folder
> ></folder><folder
> id="270"><name>Appointments</name></folder><folder
> id="271"><name>Bookmarks</name></folder><folder
> id="272"><name>Contacts</name></folder><folder
> id="265"><name>Drafts</name></folder><folder
> id="273"><name>Events</name></folder><folder
> id="274"><name>Files</name></folder><folder
> id="264"><name>Inbox</name><folder
> id="428"><name>?etrk?jis</name><description>Shit
> happens</description><folder
> id="429"><name>Hahols</name><description>Shit
> happens</description><folder
> id="465"><name>ohoo</name></folder></folder><folder
> id="430"><name>Krauklis</name><description>Shit
> happens</description></folder></folder></folder><folder
> id="275"><name>Journal</name></folder><folder
> id="276"><name>Notes</name></folder><folder
> id="266"><name>Outbox</name></folder><folder
> id="268"><name>Recycle Bin</name><folder
> id="464"><name>vitaly</name></folder></folder><folder
> id="267"><name>Sent Items</name></folder><folder
> id="277"><name>Tasks</name></folder></folder></FolderTree>
> </portlet>
> 
> However, the error somehow occurs on the transformation of 
> XML to HTML.
> 
> Any ideas?
> Neeme
> 
> The other stylesheets are included:
> 
> XSP logicsheet (one-xsp.xsl):
> <?xml version="1.0"?>
> 
> <xsl:stylesheet version="1.0"
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xmlns:xsp="http://www.apache.org/1999/XSP/Core"
> 	xmlns:one="http://www.one.lv/Utils"
> >
> 
> <xsl:template match="portlet">
> 
> <xsl:processing-instruction
> name="cocoon-process">type="xsp"</xsl:processing-instruction>
>     <xsl:processing-instruction
> name="cocoon-process">type="xslt"</xsl:processing-instruction>
>     <xsl:processing-instruction
> name="xml-stylesheet">href="one-html-list.xsl"
> type="text/xsl"</xsl:processing-instruction>
> <xsp:page language="java"
> xmlns:xsp="http://www.apache.org/1999/XSP/Core">
> 	<xsp:structure>
> 		<xsp:include>diweb.bo.*</xsp:include>
> 	</xsp:structure>
> 	<xsp:logic><![CDATA[
> 		private String normalize(String string)
> 		{
> 			if (string == null) return "";
> 			else return string;
> 		}
> 
> 		private Node BuildTree( Document doc, FolderTree tree,
> long SelectedID, long RemovedID ) throws Exception
> 		{
> 			Node result = null;
> 
> 			if ( tree == null )
> 				return result;
> 
> 			Folder folder = tree.getRoot();
> 			long ID = folder.getId();
> 
> 			if (ID == RemovedID)
> 				return result;
> 
> 			result = doc.createElement("folder");
> 			((Element) result).setAttribute( "ID",
> String.valueOf(ID) );
> 			if (ID == SelectedID)
> 				((Element) result).setAttribute(
> "IsSelected", "1" );
> 			result.appendChild( doc.createElement("name")
> ).appendChild( doc.createTextNode(folder.getName()) );
> 			String desc = folder.getDescription();
> 			if (desc.length() > 0)
> 				result.appendChild(
> doc.createElement("description") ).appendChild( 
> doc.createTextNode(desc)
> );
> 
> 			if (tree.getNodes() != null)
> 			{
> 				Node children = null;
> 				for (int i = 0; i <
> tree.getNodes().length; i++)
> 				{
> 					children = BuildTree( doc,
> tree.getNodes()[i], SelectedID, RemovedID );
> 					if (children != null)
> 						result.appendChild (
> children );
> 				}
> 			}
> 
> 			return result;
> 		}
> 
> //		int UserID = data.getUser().getId();
> 	]]></xsp:logic>
> 
> 	<xsl:copy>
> 		<xsl:apply-templates/>
> 	</xsl:copy>
> 
> </xsp:page>
> 
> </xsl:template>
> 
>   <xsl:template match="FolderTree">
> 	<FolderTree>
>    <xsp:logic>
> 			int UserID = <xsl:value-of select="@UserID"/>;
> 			long SelectedID = <xsl:value-of
> select="@SelectedID"/>;
> 			long RemovedID = <xsl:value-of
> select="@RemovedID"/>;
> 			FolderTree tree =
> FolderUtility.getTreeByUser(UserID, UserID);
> 			Node node = BuildTree( document, tree,
> SelectedID, RemovedID);
> 	
> xspCurrentNode.appendChild(document.importNode(node, true));
>    </xsp:logic>
> 	</FolderTree>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> And XML -> HTML stylesheet (one-html-list.xsl):
> <?xml version="1.0"?>
> 
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
> <xsl:template match="portlet">
>    <xsl:processing-instruction
> name="cocoon-format">type="text/html"</xsl:processing-instruction>
>    <html>
>     <head>
>      <title><xsl:value-of select="//folder/name"/></title>
>     </head>
>     <body>
> 
> 		<xsl:apply-templates/>
> 
> 		</body>
> 	</html>
> </xsl:template>
> 
>   <xsl:template match="FolderTree">
> 		<ul>
> 		<xsl:apply-templates/>
> 		</ul>
>   </xsl:template>
> 
>   <xsl:template match="portlet">
> 		<xsl:apply-templates/>
>   </xsl:template>
> 
>   <xsl:template match="folder">
> 		<li><xsl:value-of select="name"/>
> 		<xsl:if test="folder">
> 		<ul>
> 		<xsl:apply-templates select="folder"/>
> 		</ul>
> 		</xsl:if>
> 		</li>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 

Mime
View raw message