Solved

Problem with XSP, nothing is displayed??

Posted on 2004-03-23
15
520 Views
Last Modified: 2007-12-19
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
Comment
Question by:bazbazbaz
  • 9
  • 5
15 Comments
 
LVL 12

Expert Comment

by:dfiala13
ID: 10657802
Try this:

 <xsl:template match="xsp:page/tables">
0
 

Author Comment

by:bazbazbaz
ID: 10658641
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
 
LVL 12

Expert Comment

by:dfiala13
ID: 10658708
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:bazbazbaz
ID: 10658766
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
 
LVL 12

Accepted Solution

by:
dfiala13 earned 200 total points
ID: 10658804
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
 

Author Comment

by:bazbazbaz
ID: 10658842
It now gives the error: The prefix "xsl" for element "xsl:stylesheet" is not bound. Unable to get transformer handler for XSL file.
0
 

Author Comment

by:bazbazbaz
ID: 10658876
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
 

Author Comment

by:bazbazbaz
ID: 10658904
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
 
LVL 12

Expert Comment

by:dfiala13
ID: 10658980
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
 

Author Comment

by:bazbazbaz
ID: 10658999
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
 
LVL 12

Expert Comment

by:dfiala13
ID: 10659039
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
 

Author Comment

by:bazbazbaz
ID: 10659108
Can anyone else help me out on his one please, and I can split the points???
0
 

Author Comment

by:bazbazbaz
ID: 10660361
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
 
LVL 15

Expert Comment

by:dualsoul
ID: 10660753
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
 

Author Comment

by:bazbazbaz
ID: 10661032
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question