Solved

Problem with XSP, nothing is displayed??

Posted on 2004-03-23
15
502 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RSS Feed Validation 2 59
Getting attribute Values using xslt 4 41
xpath sql query 2008 8 44
MS Access XML API HTTP POST Call Object Send Not Working Correctly 15 38
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

25 Experts available now in Live!

Get 1:1 Help Now