Torsten Curdt a écrit :
> 
> While working on a logicsheet I discovered a strange
> behavior. Can anyone verify that the following might
> be a bug:
> 
> This is just a stupid example:
>  <xsp:logic>
>  Iterator i;
>  while( i.hasNext() ) {
>    Object o = i.next();
>    <xsp:element name="iteration">
>      <xsp:logic>
>      if (o instanceof String) {
>        <xsp:attribute name="type">String</xsp:attribute>      <---- NOTE THIS
>      }
>      </xsp:logic>
>      <xsp:attribute 
>name="value"><xsp:expr>String.valueOf(o)</xsp:expr></xsp:attribute>
>      <xsp:expr>String.valueOf(o)</xsp:expr>
>    </xsp:element>
>  }
>  </xsp:logic>
> 
> Becomes:
> 
>   Iterator i;
>   while( i.hasNext() ) {
>    Object o = i.next();
>    xspAttr.addAttribute("","value","value","CDATA",String.valueOf(String.valueOf(o)) 
>+ "");
> -->this.contentHandler.startElement("","iteration","iteration",xspAttr);
>    xspAttr.clear();
>    if (o instanceof String) {
> -->  xspAttr.addAttribute("","type","type","CDATA","String" + "");
>    }
>    XSPObjectHelper.xspExpr(contentHandler,String.valueOf(o));
>    this.contentHandler.endElement("","iteration","iteration");
>  }
> 
> As you see the xsp:attribute inside the xsp:logic tag is not part of the desired 
>element.
> Did I miss something or is this a bug?
> --
> Torsten
> 
This is a semi-bug :)

It's a regression from the Cocoon1 DOM-based XSP engine : in DOM,
attributes are added to an element _after_ it is created and so can
appear anywhere in the element, while in SAX attributes are set up
_before_ startElement().

So in C2, xsp.xsl scans the immediate <xsp:attribute> (1 level deep)
children of an element and inserts the corresponding code before
startElement(). <xsp:attribute> inside <xsp:logic> is therefore ignored
and wrongly added to the next produced element.

I patched xsp.xsl (lastest CVS both C2.0 and C2.1) to allow conditional
attributes like in your example. A side effect is that the corresponding
<xsp:logic> block is executed _before_ the element. So you have to be
careful about variables declarations and values.
-- 
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to