Solved

Problem with XSP, nothing is displayed??

Posted on 2004-03-23
15
489 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now