• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

Problem with XSP, nothing is displayed??

Hi,

When I use the following stylesheet with the following XML document in Cocoon nothing appears. The values are taken from a simple HTML file. Could someone tell me what's wrong please.
________________________________________________________________________________
tablesXSP.html:
<html>
<head>
<title>Pick a table to view using XSP</title>
</head>

<body>
<h1 align="center"><i>Choose a table</i></h1>
<center>
<form action="tablesXSP.xml" method="POST">
Table Name:
<select name="tableName">
<option value="students">Students Table</option>
<option value="subjects">Subjects Table</option>
</select>
<br/><br/><br/>
<input type="submit" value="Go"/>
</form>
</center>
</body>
</html>


________________________________________________________________________________
tablesXSP.xml:

<?xml version='1.0' encoding='ISO-8859-1'?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>

<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">

<tables>

<xsp:logic>
      boolean showStudents = true;
      boolean showSubjects = false;

      //Perform logic to get the table selected
      <![CDATA[
      String[] tableName = request.getParamaterValues("tableName");


      if(tableName!=null)
      {
            String whichTable = tableName[0];
            if(whichTable.equals("students")
            {
                  showStudents=true;
            }
            else if(whichTable.equals("subjects")
            {
                  showSubjects=true;
            }
      
      ]]>
      }


      if(showStudents)
      {
      <xsp:content>

      <table>
      <tableName>Students</tableName>
            <colDetails>
                  <colName nullable='true'>StudentID</colName>
                  <primaryKey>msg</primaryKey>
                  <colType>INTEGER</colType>
                  <colSize>11</colSize>
                  <data>
                        <value>12</value>
                                                </data>
                                                .........
                  etc.
                  <data>
                        <value>0879545123</value>
                  </data>
            </colDetails>
      </table>
      </xsp:content>
      }
      else if(showSubjects)
      {
      <xsp:content>
      <table>
      <tableName>Subjects</tableName>
            <colDetails>etc.......
      </table>
      </xsp:content>
      }
</xsp:logic>
</tables>
</xsp:page>

________________________________________________________________________________
tables2html.xsl

<?xml version="1.0"?>

<!-- CVS $Id: page2html.xsl,v 1.3 2003/05/07 19:15:51 vgritsenko Exp $ -->

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

  <xsl:template match="tables">
   <html>
   <body>
        <center>
       <font face="arial" size="2">
       <h2>XML file in HTML form:</h2>
      
      <br></br>
      <xsl:for-each select="table">

            <table border="0" width="65%" cellpadding="6">
            <th align="left"><h4>
                                 <xsl:value-of select="tableName"/></h4></th>

                  <xsl:for-each select="colDetails">
                   <tr align="left" bgcolor="akcccc">
                              
                  <td align="center">
                        <strong><xsl:value-of select="colName"/></strong>       
                        <br><xsl:if test="primaryKey='true'">
                                  <font color="red">Primary Key</font></xsl:if></br>                                    
                        <br><i>( Size:<xsl:value-of select="colSize"/>,
                        Type:<xsl:value-of select="colType"/> )</i></br>
                  </td>
                  <xsl:for-each select="data">
                        <td><xsl:value-of select="value"/></td>
                  </xsl:for-each>
                   </tr>      
                  </xsl:for-each>
            </table>
            <br><br><br><br></br></br></br></br>
            </xsl:for-each>
      </font>
      </center>
    </body>
   </html>
  </xsl:template>
</xsl:stylesheet>

Thnaks in advance.





0
bazbazbaz
Asked:
bazbazbaz
  • 9
  • 5
1 Solution
 
dfiala13Commented:
Try this:

 <xsl:template match="xsp:page/tables">
0
 
bazbazbazAuthor Commented:
I added that to the XSL document. The table values are still not displayed, just the heading 'XML file in HTML form' is displayed.
0
 
dfiala13Commented:
Well, looking at your XML that is because table is not a child of tables. You need to account for all the nodes:

<xsp:logic>
 <xsp:content>
   <table>

Change this
<xsl:for-each select="table">

to

<xsl:for-each select="xsp:logic/xsp:content/table">
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bazbazbazAuthor Commented:
When I did that it gave an error: prefix must resolve to a namespace: xsp. So I took out the xsp part, but again the values weren't displayed.
0
 
dfiala13Commented:
Need to leave in the xsp part, the prefix is part of the node name, won't find it otherwise.  You just need to tell your stylesheet how to deal with it:

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


to
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsp="http://apache.org/xsp">
0
 
bazbazbazAuthor Commented:
It now gives the error: The prefix "xsl" for element "xsl:stylesheet" is not bound. Unable to get transformer handler for XSL file.
0
 
bazbazbazAuthor Commented:
Sorry, I actually took out the xmlns for xsl, that's why it wouldn't work. I have an xmlns for xsp and xsl now and it's working. Thanks very much.
0
 
bazbazbazAuthor Commented:
One more question. I took out the CDATA part in the XML and hardcoded the boolean values. I have showStudents set to true and showSubjects set to false. So it should only show the student table, bit it shows both tables still. Is there anything wrong with the java in the XML document?
0
 
dfiala13Commented:
You override those values later, which is what might be happening.

    String whichTable = tableName[0];
          if(whichTable.equals("students")
          {
               showStudents=true;
          }
          else if(whichTable.equals("subjects")
          {
               showSubjects=true;
          }
     

Unfortunately, I know XML/XSL but know nothing about Cocoon
0
 
bazbazbazAuthor Commented:
Judging by the Java that I have in the XML document, do you think it should work?? Or should I put the Java in the XSL document?? Thanks again.
0
 
dfiala13Commented:
Agaim, I don't know.  Never have used java in this way.  My guess would be it goes in the stylesheet.  But that is just a guess.
0
 
bazbazbazAuthor Commented:
Can anyone else help me out on his one please, and I can split the points???
0
 
bazbazbazAuthor Commented:
HI again,

I copied an example from the internet, and even that wont work for me. Is there something major I'm forgetting?? Is there anything sepcial that I should check for??

Cheers
0
 
dualsoulCommented:
Hi bazbazbaz.
can't help you much, doesn't have much expirience with Apache Cocoon.

But try to ask in Java or JSP section. (i think Java most prefebably)
0
 
bazbazbazAuthor Commented:
I sorted it out. In the pipeline I needed to add a type to the generate element: <map:generate type="serverpages" src="tablesXSP.xml"/>. Thanks anyway.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now