You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kuppa Kiran Kumar <Ku...@PLANETASIA.COM> on 2001/03/10 23:07:11 UTC

xslt trasformations with cocoon 1.8

Hello All,
	I would be glad if you could help  with my  problem.
	Contents.xml is  an xsp page, which generates xml dynamically,using
local resources.
	Book.xml is a static version of the saame process.

	book_index.xsl is a style sheet which renders the xml to html.
	It is working perfectly fine if itry to display Book.xml my  browser
(IE 5.5)	. Butnothing is showing up with the dynamic counter part of
the xml file.

Here is Book.xml


<?xml version ="1.0"?>

<?xml-stylesheet type ="text/xsl" href="book_index2.xsl"?>
<Book>
	<chapter num="1">
		<Name>Name of the first Chapter</Name>
		<section num="1">
				<Name>Name of first section in first
chapter</Name>
				<Source>Source xml file of this
section</Source>
		</section>
		<section num="2">
				<Name>Name of the second section in first
chapter</Name>
				<Source>Source xml file of this
section</Source>
		</section>
  </chapter>
  <chapter num="2">
		<Name>Name of the Second Chapter</Name>
			<section num="1">
					<Name>Name of first section in
Second chapter</Name>
					<Source>Source xml file of this
section</Source>
			</section>
			<section num="2">
				<Name>Name of first section in Second
chapter</Name>
				<Source>Source xml file of this
section</Source>
		</section>
			<section num="3">
				<Name>Name of Third section in Second
chapter</Name>
				<Source>Source xml file of this
section</Source>
		</section>
	</chapter>
</Book>

Contents.xml

<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet type="text/xsl" href="book_index5.xsl"?>
<xsp:page xmlns:xsp ="http://www.apache.org/1999/XSP/Core">
	<xsp:structure>
		<xsp:include>myLibrary.Navneet.Chapter</xsp:include>
		<xsp:include>myLibrary.Navneet.ChapterFiles</xsp:include>
	</xsp:structure>
	<xsp:logic>
		ChapterFiles chapterFiles =new ChapterFiles(".")	;
		Vector chapterList = chapterFiles.getChapters();
		int numberofChapts = chapterList.size();
	</xsp:logic>
	<Book>
		<xsp:logic>			
			
				for(int i=0;i&lt;numberofChapts;i++)
				{
					<xsp:element name="Chapter">
						<xsp:attribute name="num">
							
	
<xsp:expr>i</xsp:expr>
						</xsp:attribute>	
						<xsp:logic>
							Chapter chapter
=(Chapter)chapterList.get(i);
							<xsp:content>	
								<Name>
	
<xsp:expr>chapter.getChapterName()</xsp:expr>
								</Name>
							</xsp:content>
							String sections[]
=chapter.getAllSections();
							for(int
j=0;j&lt;sections.length;j++)	
							{
								<Section>
	
<xsp:attribute name="num">
	
<xsp:expr>j</xsp:expr>
	
</xsp:attribute>
	
<Name><xsp:expr>sections[i]</xsp:expr></Name>
	
<source>http://kiran:8080/cocoon/samples/Book/
	
<xsp:expr>chapter.getChapterName()</xsp:expr>/
	
<xsp:expr>sections[i]</xsp:expr>	
	
</source>	
								</Section>
							}	
						</xsp:logic>	
	
<SomeElement>SomeContent</SomeElement>
					</xsp:element>	
						
					
				}
		</xsp:logic>

	</Book>
</xsp:page>

book_index.xsl


<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0"
>
<xsl:template match="/">
	<html>
	<head><title>Chapter Contents</title></head>
	<body>
	<xsl:apply-templates select="Book"/>
	</body>
	</html>
</xsl:template>
	<xsl:template match="Book">
	
	<xsl:apply-templates select="chapter"/>
	</xsl:template>
		<xsl:template match="chapter">
		<h3>Chapter :<xsl:value-of select="@num"/></h3>
			<h3><i ><b><xsl:value-of
select="Name"/></b></i></h3>      
			<br/>	
		<xsl:apply-templates select="section"/>
		</xsl:template>

			<xsl:template match="section">
				<h6><xsl:value-of select ="@num"/>.</h6>
				<xsl:element name ="a">
					<xsl:attribute name="href">
						<xsl:value-of
select="Source"/>
					</xsl:attribute>
					<h6><xsl:value-of
select="Name"/></h6>
				</xsl:element>
				<br/>
			</xsl:template>
</xsl:stylesheet>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: xslt trasformations with cocoon 1.8

Posted by "Eric A. Sirois" <ea...@hotmail.com>.
Hello,

For now, Cocoon does not support "text/xml" and "appliaction/xml" so leave
it as "text/xsl" for know.  For it to support it you have to change a line
of code in XSLTProcessor.java.  To get it download it from the code
repository v1.32 has the fix.

The reason you stylesheet is not working is an XPath issue.  In you XML file
you have the namespace "xsp" assigned to the document., but in your
staylesheet you are leaving out the path the the elements.  For instance,
the XPath to Book is not /Book, it's /xsp:page/Book and for chapter it's not
/Book/chapter it's /xsp:page/Book/xsp:logic/xsp:element/@name.

I' ve modified the XML file and the XSL file to add a default namesapce
http://www.foobar.com.  I got stuf to come out, but I've never used XSP so
I'm not sure if it's right.

HTH,

Eric

--------------------xml file ----------------------------------------
<?xml-stylesheet type="text/xsl" href="book_index5.xsl"?>
<xsp:page xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns="http://www.foobar.com">


----------------book_index5.xsl-----------------------------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:test="http://www.foobar.com" version="1.0">
 <xsl:template match="/">
  <xsl:apply-templates select="/xsp:page"/>
 </xsl:template>
 <xsl:template match="/xsp:page">
  <html>
   <head>
    <title>Chapter Contents</title>
   </head>
   <body>
    <xsl:apply-templates select="test:Book"/>
i'am in
</body>
  </html>
 </xsl:template>
 <xsl:template match="/test:Book">
i'am in 2
<xsl:apply-templates select="/xsp:logic/xsp:element/@name"/>
 </xsl:template>
 <xsl:template match="/xsp:logic/xsp:element/@namer">
  <h3>Chapter :<xsl:value-of select="@num"/>
  </h3>
  <h3>
   <i>
    <b>
     <xsl:value-of select="Name"/>
    </b>
   </i>
  </h3>
  <br/>
  <xsl:apply-templates select="section"/>
 </xsl:template>
 <xsl:template match="section">
  <h6>
   <xsl:value-of select="@num"/>.</h6>
  <xsl:element name="a">
   <xsl:attribute name="href"><xsl:value-of
select="Source"/></xsl:attribute>
   <h6>
    <xsl:value-of select="Name"/>
   </h6>
  </xsl:element>
  <br/>
 </xsl:template>
</xsl:stylesheet>

----- Original Message -----
From: "Piroumian, Konstantin" <KP...@flagship.ru>
To: <co...@xml.apache.org>
Sent: Sunday, March 11, 2001 6:39 AM
Subject: Re: xslt trasformations with cocoon 1.8


> Try to look to the results of your Contents.xml by replacing:
>  <?cocoon-process type="xslt"?>
>  <?xml-stylesheet type="text/xsl" href="book_index5.xsl"?>
> by
> <?cocoon-format type="text/xml"?>
>
> Maybe something wrong with your XSP.
>
> Regards,
>     Konstantin Piroumian.
>
> ----- Original Message -----
> From: "Kuppa Kiran Kumar" <Ku...@PLANETASIA.COM>
> To: <co...@xml.apache.org>
> Sent: Sunday, March 11, 2001 1:07 AM
> Subject: xslt trasformations with cocoon 1.8
>
>
> > Hello All,
> > I would be glad if you could help  with my  problem.
> > Contents.xml is  an xsp page, which generates xml dynamically,using
> > local resources.
> > Book.xml is a static version of the saame process.
> >
> > book_index.xsl is a style sheet which renders the xml to html.
> > It is working perfectly fine if itry to display Book.xml my  browser
> > (IE 5.5) . Butnothing is showing up with the dynamic counter part of
> > the xml file.
> >
> > Here is Book.xml
> >
> >
> > <?xml version ="1.0"?>
> >
> > <?xml-stylesheet type ="text/xsl" href="book_index2.xsl"?>
> > <Book>
> > <chapter num="1">
> > <Name>Name of the first Chapter</Name>
> > <section num="1">
> > <Name>Name of first section in first
> > chapter</Name>
> > <Source>Source xml file of this
> > section</Source>
> > </section>
> > <section num="2">
> > <Name>Name of the second section in first
> > chapter</Name>
> > <Source>Source xml file of this
> > section</Source>
> > </section>
> >   </chapter>
> >   <chapter num="2">
> > <Name>Name of the Second Chapter</Name>
> > <section num="1">
> > <Name>Name of first section in
> > Second chapter</Name>
> > <Source>Source xml file of this
> > section</Source>
> > </section>
> > <section num="2">
> > <Name>Name of first section in Second
> > chapter</Name>
> > <Source>Source xml file of this
> > section</Source>
> > </section>
> > <section num="3">
> > <Name>Name of Third section in Second
> > chapter</Name>
> > <Source>Source xml file of this
> > section</Source>
> > </section>
> > </chapter>
> > </Book>
> >
> > Contents.xml
> >
> > <?xml version="1.0"?>
> > <?cocoon-process type="xsp"?>
> > <?cocoon-process type="xslt"?>
> > <?xml-stylesheet type="text/xsl" href="book_index5.xsl"?>
> > <xsp:page xmlns:xsp ="http://www.apache.org/1999/XSP/Core">
> > <xsp:structure>
> > <xsp:include>myLibrary.Navneet.Chapter</xsp:include>
> > <xsp:include>myLibrary.Navneet.ChapterFiles</xsp:include>
> > </xsp:structure>
> > <xsp:logic>
> > ChapterFiles chapterFiles =new ChapterFiles(".") ;
> > Vector chapterList = chapterFiles.getChapters();
> > int numberofChapts = chapterList.size();
> > </xsp:logic>
> > <Book>
> > <xsp:logic>
> >
> > for(int i=0;i&lt;numberofChapts;i++)
> > {
> > <xsp:element name="Chapter">
> > <xsp:attribute name="num">
> >
> >
> > <xsp:expr>i</xsp:expr>
> > </xsp:attribute>
> > <xsp:logic>
> > Chapter chapter
> > =(Chapter)chapterList.get(i);
> > <xsp:content>
> > <Name>
> >
> > <xsp:expr>chapter.getChapterName()</xsp:expr>
> > </Name>
> > </xsp:content>
> > String sections[]
> > =chapter.getAllSections();
> > for(int
> > j=0;j&lt;sections.length;j++)
> > {
> > <Section>
> >
> > <xsp:attribute name="num">
> >
> > <xsp:expr>j</xsp:expr>
> >
> > </xsp:attribute>
> >
> > <Name><xsp:expr>sections[i]</xsp:expr></Name>
> >
> > <source>http://kiran:8080/cocoon/samples/Book/
> >
> > <xsp:expr>chapter.getChapterName()</xsp:expr>/
> >
> > <xsp:expr>sections[i]</xsp:expr>
> >
> > </source>
> > </Section>
> > }
> > </xsp:logic>
> >
> > <SomeElement>SomeContent</SomeElement>
> > </xsp:element>
> >
> >
> > }
> > </xsp:logic>
> >
> > </Book>
> > </xsp:page>
> >
> > book_index.xsl
> >
> >
> > <?xml version="1.0"?>
> > <xsl:stylesheet
> >   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >   version="1.0"
> > >
> > <xsl:template match="/">
> > <html>
> > <head><title>Chapter Contents</title></head>
> > <body>
> > <xsl:apply-templates select="Book"/>
> > </body>
> > </html>
> > </xsl:template>
> > <xsl:template match="Book">
> >
> > <xsl:apply-templates select="chapter"/>
> > </xsl:template>
> > <xsl:template match="chapter">
> > <h3>Chapter :<xsl:value-of select="@num"/></h3>
> > <h3><i ><b><xsl:value-of
> > select="Name"/></b></i></h3>
> > <br/>
> > <xsl:apply-templates select="section"/>
> > </xsl:template>
> >
> > <xsl:template match="section">
> > <h6><xsl:value-of select ="@num"/>.</h6>
> > <xsl:element name ="a">
> > <xsl:attribute name="href">
> > <xsl:value-of
> > select="Source"/>
> > </xsl:attribute>
> > <h6><xsl:value-of
> > select="Name"/></h6>
> > </xsl:element>
> > <br/>
> > </xsl:template>
> > </xsl:stylesheet>
> >
> >
> > ---------------------------------------------------------------------
> > Please check that your question has not already been answered in the
> > FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> >
> > To unsubscribe, e-mail: <co...@xml.apache.org>
> > For additional commands, e-mail: <co...@xml.apache.org>
> >
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>
>

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: xslt trasformations with cocoon 1.8

Posted by "Piroumian, Konstantin" <KP...@flagship.ru>.
Try to look to the results of your Contents.xml by replacing:
 <?cocoon-process type="xslt"?>
 <?xml-stylesheet type="text/xsl" href="book_index5.xsl"?>
by
<?cocoon-format type="text/xml"?>

Maybe something wrong with your XSP.

Regards,
    Konstantin Piroumian.

----- Original Message ----- 
From: "Kuppa Kiran Kumar" <Ku...@PLANETASIA.COM>
To: <co...@xml.apache.org>
Sent: Sunday, March 11, 2001 1:07 AM
Subject: xslt trasformations with cocoon 1.8


> Hello All,
> I would be glad if you could help  with my  problem.
> Contents.xml is  an xsp page, which generates xml dynamically,using
> local resources.
> Book.xml is a static version of the saame process.
> 
> book_index.xsl is a style sheet which renders the xml to html.
> It is working perfectly fine if itry to display Book.xml my  browser
> (IE 5.5) . Butnothing is showing up with the dynamic counter part of
> the xml file.
> 
> Here is Book.xml
> 
> 
> <?xml version ="1.0"?>
> 
> <?xml-stylesheet type ="text/xsl" href="book_index2.xsl"?>
> <Book>
> <chapter num="1">
> <Name>Name of the first Chapter</Name>
> <section num="1">
> <Name>Name of first section in first
> chapter</Name>
> <Source>Source xml file of this
> section</Source>
> </section>
> <section num="2">
> <Name>Name of the second section in first
> chapter</Name>
> <Source>Source xml file of this
> section</Source>
> </section>
>   </chapter>
>   <chapter num="2">
> <Name>Name of the Second Chapter</Name>
> <section num="1">
> <Name>Name of first section in
> Second chapter</Name>
> <Source>Source xml file of this
> section</Source>
> </section>
> <section num="2">
> <Name>Name of first section in Second
> chapter</Name>
> <Source>Source xml file of this
> section</Source>
> </section>
> <section num="3">
> <Name>Name of Third section in Second
> chapter</Name>
> <Source>Source xml file of this
> section</Source>
> </section>
> </chapter>
> </Book>
> 
> Contents.xml
> 
> <?xml version="1.0"?>
> <?cocoon-process type="xsp"?>
> <?cocoon-process type="xslt"?>
> <?xml-stylesheet type="text/xsl" href="book_index5.xsl"?>
> <xsp:page xmlns:xsp ="http://www.apache.org/1999/XSP/Core">
> <xsp:structure>
> <xsp:include>myLibrary.Navneet.Chapter</xsp:include>
> <xsp:include>myLibrary.Navneet.ChapterFiles</xsp:include>
> </xsp:structure>
> <xsp:logic>
> ChapterFiles chapterFiles =new ChapterFiles(".") ;
> Vector chapterList = chapterFiles.getChapters();
> int numberofChapts = chapterList.size();
> </xsp:logic>
> <Book>
> <xsp:logic> 
> 
> for(int i=0;i&lt;numberofChapts;i++)
> {
> <xsp:element name="Chapter">
> <xsp:attribute name="num">
> 
> 
> <xsp:expr>i</xsp:expr>
> </xsp:attribute> 
> <xsp:logic>
> Chapter chapter
> =(Chapter)chapterList.get(i);
> <xsp:content> 
> <Name>
> 
> <xsp:expr>chapter.getChapterName()</xsp:expr>
> </Name>
> </xsp:content>
> String sections[]
> =chapter.getAllSections();
> for(int
> j=0;j&lt;sections.length;j++) 
> {
> <Section>
> 
> <xsp:attribute name="num">
> 
> <xsp:expr>j</xsp:expr>
> 
> </xsp:attribute>
> 
> <Name><xsp:expr>sections[i]</xsp:expr></Name>
> 
> <source>http://kiran:8080/cocoon/samples/Book/
> 
> <xsp:expr>chapter.getChapterName()</xsp:expr>/
> 
> <xsp:expr>sections[i]</xsp:expr> 
> 
> </source> 
> </Section>
> } 
> </xsp:logic> 
> 
> <SomeElement>SomeContent</SomeElement>
> </xsp:element> 
> 
> 
> }
> </xsp:logic>
> 
> </Book>
> </xsp:page>
> 
> book_index.xsl
> 
> 
> <?xml version="1.0"?>
> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   version="1.0"
> >
> <xsl:template match="/">
> <html>
> <head><title>Chapter Contents</title></head>
> <body>
> <xsl:apply-templates select="Book"/>
> </body>
> </html>
> </xsl:template>
> <xsl:template match="Book">
> 
> <xsl:apply-templates select="chapter"/>
> </xsl:template>
> <xsl:template match="chapter">
> <h3>Chapter :<xsl:value-of select="@num"/></h3>
> <h3><i ><b><xsl:value-of
> select="Name"/></b></i></h3>      
> <br/> 
> <xsl:apply-templates select="section"/>
> </xsl:template>
> 
> <xsl:template match="section">
> <h6><xsl:value-of select ="@num"/>.</h6>
> <xsl:element name ="a">
> <xsl:attribute name="href">
> <xsl:value-of
> select="Source"/>
> </xsl:attribute>
> <h6><xsl:value-of
> select="Name"/></h6>
> </xsl:element>
> <br/>
> </xsl:template>
> </xsl:stylesheet>
> 
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
> 

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>