You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Carmona Perez, David" <DP...@fcc.es> on 2003/11/20 09:43:10 UTC

Possible bug in XSP generator

Hi all,
 
I have this snippet in an XSP file:
 
<xsp:logic>
      for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
      String mod = it.next().toString();
            <xsp:expr>mod</xsp:expr><br/>
      }
</xsp:logic>
 
and the following code is generated:
 
for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
                        String mod = it.next().toString();
(mod)
this.contentHandler.startElement("", "br", "br", xspAttr);
    xspAttr.clear();
            }
 
 
I think that the right code would be:
 
for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
                        String mod = it.next().toString();
this.characters(mod);                           <------------------------
this.contentHandler.startElement("", "br", "br", xspAttr);
    xspAttr.clear();
            }
 
Is this really a bug of the XSP generator?
--------
David
 

Re: Possible bug in XSP generator

Posted by Joerg Heinicke <jh...@virbus.de>.
Antonio Gallardo wrote:
> Try this:
> 
> <xsp:logic>
>   for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
> </xsp:logic>
>   <xsp:expr>it.next().toString()</xsp:expr><br/>
> <xsp:logic>
>   }
> </xsp:logic>

Uh, that's ugly! I feel reminded to println("<html><head>") code! I much 
more like David's approach using an additional <span>.

The reason for this XSP bug is the stylesheet. Around line 400 there is a 
template

<xsl:template match="xsp:expr">
   <xsl:choose>
     <xsl:when test="namespace-uri(..) = $xsp-uri and local-name(..) !=
                     'content' and local-name(..) != 'element'">
       <!--
            Expression is nested inside another XSP tag:
            preserve its Java type
       -->
       (<xsl:value-of select="."/>)
     </xsl:when>
     <xsl:when test="string-length(.) = 0">
       <!-- Do nothing -->
     </xsl:when>
     <xsl:otherwise>
       <!-- Output the value as elements or character data depending on its
            type -->
       XSPObjectHelper.xspExpr(contentHandler, <xsl:value-of select="."/>);
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

As you can see the first option tests for a surrounding XSP element as 
xsp:logic is one (and probably also your parent element of xsp:logic, this 
is why Antonio's approach also fails). But I don't know what exactly is the 
use case for this. Maybe somebody else can shed some light on this?

Joerg

> Carmona Perez, David dijo:
> 
>>Hi all,
>>
>>I have this snippet in an XSP file:
>>
>><xsp:logic>
>>      for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext();
>>) {
>>      String mod = it.next().toString();
>>            <xsp:expr>mod</xsp:expr><br/>
>>      }
>></xsp:logic>
>>
>>and the following code is generated:
>>
>>for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
>>                        String mod = it.next().toString();
>>(mod)
>>this.contentHandler.startElement("", "br", "br", xspAttr);
>>    xspAttr.clear();
>>            }
>>
>>
>>I think that the right code would be:
>>
>>for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
>>                        String mod = it.next().toString();
>>this.characters(mod);                           <------------------------
>>this.contentHandler.startElement("", "br", "br", xspAttr);
>>    xspAttr.clear();
>>            }
>>
>>Is this really a bug of the XSP generator?
>>--------
>>David

-- 
System Development
VIRBUS AG
Fon  +49(0)341-979-7419
Fax  +49(0)341-979-7409
joerg.heinicke@virbus.de
www.virbus.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Possible bug in XSP generator

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Try this:

<xsp:logic>
  for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
</xsp:logic>
  <xsp:expr>it.next().toString()</xsp:expr><br/>
<xsp:logic>
  }
</xsp:logic>

Best Regards,

Antonio Gallardo

Carmona Perez, David dijo:
> Hi all,
>
> I have this snippet in an XSP file:
>
> <xsp:logic>
>       for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext();
> ) {
>       String mod = it.next().toString();
>             <xsp:expr>mod</xsp:expr><br/>
>       }
> </xsp:logic>
>
> and the following code is generated:
>
> for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
>                         String mod = it.next().toString();
> (mod)
> this.contentHandler.startElement("", "br", "br", xspAttr);
>     xspAttr.clear();
>             }
>
>
> I think that the right code would be:
>
> for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
>                         String mod = it.next().toString();
> this.characters(mod);                           <------------------------
> this.contentHandler.startElement("", "br", "br", xspAttr);
>     xspAttr.clear();
>             }
>
> Is this really a bug of the XSP generator?
> --------
> David
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Possible bug in XSP generator

Posted by Olivier Billard <ob...@rennes.jouve.fr>.
Hi David,

If you want to output content in an <xsp:logic> tag, you must use <xsp:content> :

<xsp:logic>
   for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
     String mod = it.next().toString();
     <xsp:content><xsp:expr>mod</xsp:expr><br/></xsp:content>
   }
</xsp:logic>

PS : Please write your mails in plain text

-- 
Olivier Billard


On 20/11/2003 09:43, Carmona Perez, David wrote:

> Hi all,
> 
>  
> 
> I have this snippet in an XSP file:
> 
>  
> 
> <xsp:logic>
> 
>       for (java.util.Iterator it = ajs.getMods().iterator(); 
> it.hasNext(); ) {
> 
>       String mod = it.next().toString();
> 
>             <xsp:expr>mod</xsp:expr><br/>
> 
>       }
> 
> </xsp:logic>
> 
>  
> 
> and the following code is generated:
> 
>  
> 
> for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
> 
>                         String mod = it.next().toString();
> 
> (mod)
> 
> this.contentHandler.startElement("", "br", "br", xspAttr);
> 
>     xspAttr.clear();
> 
>             }
> 
>  
> 
>  
> 
> I think that the right code would be:
> 
>  
> 
> for (java.util.Iterator it = ajs.getMods().iterator(); it.hasNext(); ) {
> 
>                         String mod = it.next().toString();
> 
> *this.characters(*mod*)*;                           
> <------------------------
> 
> this.contentHandler.startElement("", "br", "br", xspAttr);
> 
>     xspAttr.clear();
> 
>             }
> 
>  
> 
> Is this really a bug of the XSP generator?
> 
> /--------/
> 
> /David/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org