You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by JAMES VANETTEN <JV...@ALLMERICA.COM> on 2000/04/03 19:38:51 UTC

JAVA servlet with XML and Cocoon

I have Cocoon working on my server. It works fine when I put the XML in the web directory and click on the url. What I want to do is have a JAVA program generate dynamic XML and have Cocoon process it.

I put the XML in my servlet and when I run the servlet using IE5.0 I see the XML source. I concluded that Cocoon is not converting the XML to HTML. How do I get Cocoon to process XML content generated from a JAVA servlet??

Thanks
Jim


What stylesheet might I use to parse the xml...

Posted by Matthew Cordes <mc...@maine.edu>.
Hello, I have some xml that I want to reorder, but leave in xml format 
via an xsl.  What I have right now isn't working, please help.


Starting xml:

<resultset>
    <result>
        <name>  Art </name>
        <age>   22  </age>
        <course>    mes-399 </course>
    </result>
    <result>
        <name>  Pat </name>
        <age>   22  </age>
        <course>    cos-399 </course>
    </result>
    <result>
        <name>  Stan </name>
        <age>   45  </age>
        <course>    mes-399 </course>
    </result>
    <result>
        <name>  Jimmy </name>
        <age>   23  </age>
        <course>    cos-399 </course>
    </result>
</resultset>


Here is the stylesheet I used,

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <courses>
        <xsl:apply-templates select="/resultset/result"/>
    </courses>
</xsl:template>

<xsl:template match="result">
    <course>
        <xsl:attribute name="title">
            <xsl:value-of select="course"/>
        </xsl:attribute>
		<student>
	        <name> <xsl:value-of select="name"/> </name>
	        <age> <xsl:value-of select="age"/> </age>
		</student>
    </course>
</xsl:template>
</xsl:stylesheet>


together these output: 


<?xml version="1.0" encoding="ISO-8859-1"?>
<courses>
	<course title="mes-399">
		<student>
			<name> Art </name>
			<age>22</age>
		</student>	
	</course>
	<course title="cos-399">
		<student>
			<name> Pat </name>
			<age>22</age>
		</student>
	</course>
	<course title="mes-399">
		<student>
			<name> Stan </name>
			<age>45</age>
		</student>
	</course>
	<course title="cos-399">
		<student>
			<name> Jimmy </name>
			<age>23</age>
		</student>
	</course>
</courses>


when I really wanted this output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<courses>
	<course title="mes-399">
		<student>
			<name> Art </name>
			<age>22</age>
		</student>
		<student>
			<name> Stan </name>
			<age>45</age>
		</student>
	</course>
	<course title="cos-399">
		<student>
			<name> Pat </name>
			<age>22</age>
		</student>	
		<student>
			<name> Jimmy </name>
			<age>23</age>
		</student>	
	</course>
</courses>

Notice how the desired xml above is grouped by course, while the real
output is not.  Can anyone help me do it this way?

Perhaps also, some kind of xsl that would allow me to compress nodes with
the same name would also work (e.g., above, <course title="cos-399">
appears twice, but I really only want it once ).

Thanks for reading this,

-matt


Cocoon 1.7.2 installation problems

Posted by Marcello Granata <mg...@matrix.it>.
I've got a strange (it seems to me) problem. I had a working Cocoon 1.7.1.
Now I upgraded but, when i try to get a simple xml file i get the following
error:
"java.lang.RuntimeException: Error creating
org.apache.cocoon.parser.XercesParser: make sure the needed classes can be
found in the classpath (org/apache/xerces/framework/XMLParser) ..."

I didn't change anything in my Jrun (my servlet engine) configuration.
So ... what did i forget?

Any help welcome, thanks, marcello



Re: JAVA servlet with XML and Cocoon

Posted by Russell Castagnaro <ru...@synctank.com>.
James,

You can Either make a Cocoon producer that access a servlet to get the XML, then use a sylesheet of your making.

Here's a basic servlet I use.  Added as an attachment.  Its easy to get the input source from a url instead...


-rrc


JAMES VANETTEN wrote:

> I have Cocoon working on my server. It works fine when I put the XML in the web directory and click on the url. What I want to do is have a JAVA program generate dynamic XML and have Cocoon process it.
>
> I put the XML in my servlet and when I run the servlet using IE5.0 I see the XML source. I concluded that Cocoon is not converting the XML to HTML. How do I get Cocoon to process XML content generated from a JAVA servlet??
>
> Thanks
> Jim
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

--

Russell Castagnaro
Chief Mentor
SyncTank Solutions
http://www.synctank.com

Earth is the cradle of mankind; one does not remain in the cradle forever
-Tsiolkovsky


Re: JAVA servlet with XML and Cocoon

Posted by Ulrich Mayring <u...@123.org>.
JAMES VANETTEN wrote:
> 
> I put the XML in my servlet and when I run the servlet using IE5.0 I see
> the XML source. I concluded that Cocoon is not converting the XML to HTML.
> How do I get Cocoon to process XML content generated from a JAVA servlet??

Put your servlet's code in an XSP page?

SCNR,

Ulrich

-- 
Ulrich Mayring
u@123.org