cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luís Góis <luisg...@netc.pt>
Subject RE: xsp:attribute generating a new element instead of an attribute in an already existing element
Date Tue, 31 Dec 2002 15:03:40 GMT
In my last e-mail I've used a diferent XML tree sample than the one I initially posted here.
I wan't to generate a XML tree like this :
 
>     >     >>expected XML :
>     >     >>=========
>     >     >><dates current="30-12-2002">
>     >     >>  <date_sel>27-12-2002</date_sel>
>     >     >>  <date_sel>24-12-2002</date_sel>
>     >     >></dates>

so <dates> must be placed outside the while loop.
 
The code in my previous mail works, I just don't think that the extra </xsp:logic><xsp:logic>
after <xsp:attribute> is an API limitation !;)

	-----Mensagem original----- 
	De: Jim Bearce [mailto:jim@bearce.us] 
	Enviada: ter 31-12-2002 14:55 
	Para: Luís Góis; cocoon-users@xml.apache.org 
	Cc: 
	Assunto: Re: xsp:attribute generating a new element instead of an attribute in an already
existing element
	
	

	Yeah it probably would help if I paid attention to what I was typing,
	how about this instead?
	
	<xsp:logic>
	   while(rsDates.next()) {
	        <dates>
	        if (rsDates.getString(1).equals(today) {
	          currentDate = today;
	        }
	           <xsp:attribute 
	name="current"><xsp:expr>currentDate</xsp:expr></xsp:attribute>
	            <date_sel><xsp:expr>rsDates.getString(1)</xsp:expr></date_sel>
	        </dates>
	  }
	  </xsp:logic>
	
	Luís Góis wrote:
	
	> Your solution only works when the "if" is true for the first loop
	> iteraction. After that new child elements have been created and the
	> attribute won't be placed where I want to.
	> 
	> A working solution is -- don't try to understand the source code, just
	> look at the generated XML (grab your underware) :
	> 
	>           <dates>
	>               <xsp:logic>
	>                     ResultSet rsDates = <esql:get-resultset/>;
	>                     while(rsDates.next()) {
	>                        if (rsDates.getString(1).equals(today) {
	>                                  currentDate = today;
	>                               }
	>                               (...)
	>                                // I'm storing the rsDates here in an
	> ArrayList
	>                               (...)
	>                           }            
	>                    <xsp:attribute
	> name="current"><xsp:expr>currentDate</xsp:expr></xsp:attribute>
              
	>               <!-- GRAB YOUR UNDERWARE -->
	>               </xsp:logic>
	>               <xsp:logic>
	>               <!-- GRAB YOUR UNDERWARE -->
	>                   iter = listDates.listIterator();
	>                   while(iter.hasNext()) {
	>                       
	> <date_sel><xsp:expr>(String)iter.next()</xsp:expr></date_sel>;
	>                   }               
	>                </xsp:logic>
	>            </dates>
	> 
	> generated XML *without*  the </xsp:logic><xsp:logic>  tags between
	> the <!-- GRAB YOUR UNDERWARE --> comments.
	> ===================================================================================
	> <date_sel current="30-12-2002">30-12-2002</date_sel>
	> <dates> </dates>
	> 
	> generated XML *with*  the </xsp:logic><xsp:logic>  tags between
	> the <!-- GRAB YOUR UNDERWARE --> comments.
	> ===================================================================================
	> <dates current="30-12-2002">
	>     <date_sel >30-12-2002</date_sel>
	> </dates>
	> 
	> -----Mensagem original-----
	> *De:* Jim Bearce [mailto:jim@bearce.us]
	> *Enviada:* ter 31-12-2002 14:13
	> *Para:* cocoon-users@xml.apache.org
	> *Cc:* Luís Góis
	> *Assunto:* Re: xsp:attribute generating a new element instead of an
	> attribute in an already existing element
	>
	>     Luís,
	>
	>     I've seen the same things you have but I guess from a Cocoon
	>     perspective, it's not really an error; although it doesn't work
	>     the way
	>     you want it to.  Maybe this would help you:
	>
	>        <xsp:logic>
	>         while(rsDates.next()) {
	>              <dates>
	>              if (rsDates.getString(1).equals(today) {
	>                currentDate = today;
	>                 <xsp:attribute
	>     name="current"><xsp:expr>currentDate</xsp:expr></xsp:attribute>
	>              }
	>                
	>     <date_sel><xsp:expr>rsDates.getString(1)</xsp:expr></date_sel>
	>              </dates>
	>        }
	>        </xsp:logic>
	>
	>
	>     Luís Góis wrote:
	>
	>     > Hello Joerg.
	>     >
	>     > I was expecting some error saying I couldn't create the attribute
	>     > there, instead, I got an unexpected (from my point of view) XML
	>     tree.
	>     >
	>     > Tks
	>     >
	>     >
	>     >
	>     >     -----Mensagem original-----
	>     >     *De:* Joerg Heinicke [mailto:joerg.heinicke@gmx.de]
	>     >     *Enviada:* ter 31-12-2002 11:51
	>     >     *Para:* cocoon-users@xml.apache.org
	>     >     *Cc:*
	>     >     *Assunto:* Re: xsp:attribute generating a new element instead of
	>     >     an attribute in an already existing element
	>     >
	>     >     Hello Luis,
	>     >
	>     >     the change of currentDate doesn't change the constraints of the
	>     >     API. You
	>     >     can not create an attribute after you already have created an
	>     >     element or
	>     >     text. If you have such a dependency you must calculate
	>     currentDate
	>     >     before creating the XML (move the logic out of the XML data
	>     >     structure).
	>     >
	>     >     Joerg
	>     >
	>     >     Luis Gois wrote:
	>     >     > Hi.
	>     >     >
	>     >     > My example wasn't good enough!:( I forgot to point out that
	>     >     currentDate
	>     >     > might get changed in the while loop (see below), so that
	>     >     xsp:attribute
	>     >     > must be evaluated after the java code within the xsp:logic
	>     block.
	>     >     >
	>     >     > <dates>
	>     >     >   <xsp:logic>
	>     >     >    while(rsDates.next()) {
	>     >     >   
	>     <date_sel><xsp:expr>rsDates.getString(1)</xsp:expr></date_sel>
	>     >     >     if (rsDates.getString(1).equals(today) {
	>     >     >       currentDate = today;
	>     >     >     }
	>     >     >    }
	>     >     >    <xsp:attribute
	>     >     >
	>     name="current"><xsp:expr>currentDate</xsp:expr></xsp:attribute>
	>     >     >   </xsp:logic>
	>     >     > </dates>
	>     >     >
	>     >     >
	>     >     > -----Original Message-----
	>     >     > From: Jim Bearce [mailto:jim@bearce.us]
	>     >     > Sent: terça-feira, 31 de Dezembro de 2002 1:14
	>     >     > To: cocoon-users@xml.apache.org; luisgois@netc.pt
	>     >     > Subject: Re: xsp:attribute generating a new element
	>     instead of an
	>     >     > attribute in an already existing element
	>     >     >
	>     >     >
	>     >     > I believe you would have to do it this way:
	>     >     >
	>     >     > <dates>
	>     >     >     <xsp:attribute
	>     >     >
	>     name="current"><xsp:expr>currentDate</xsp:expr></xsp:attribute>
	>     >     >     <xsp:logic>
	>     >     >         while(rsDates.next()) {
	>     >     >
	>     >     > <data_sel><xsp:expr>rsDates.getString(1)</xsp:expr></date_sel>
	>     >     >         }
	>     >     >     </xsp:logic>
	>     >     > </dates>
	>     >     >
	>     >     > Luís Góis wrote:
	>     >     >
	>     >     >
	>     >     >>Could you comment the behaviour below :
	>     >     >>
	>     >     >>
	>     >     >>XSP :
	>     >     >>===
	>     >     >><dates>
	>     >     >> <xsp:logic>
	>     >     >>  while(rsDates.next()) {
	>     >     >> 
	>     <date_sel><xsp:expr>rsDates.getString(1)</xsp:expr></date_sel>
	>     >     >>  }
	>     >     >>  <xsp:attribute
	>     >   
	>     >>name="current"><xsp:expr>currentDate</xsp:expr></xsp:attribute>
	>     >     >> </xsp:logic>
	>     >     >></dates>
	>     >     >>
	>     >     >>generated XML :
	>     >     >>=============
	>     >     >><dates>
	>     >     >>  <date_sel>27-12-2002</date_sel>
	>     >     >>  <date_sel>24-12-2002</date_sel>
	>     >     >>  <dates current="30-12-2002"> </dates>
	>     >     >></dates>
	>     >     >>expected XML :
	>     >     >>=========
	>     >     >><dates current="30-12-2002">
	>     >     >>  <date_sel>27-12-2002</date_sel>
	>     >     >>  <date_sel>24-12-2002</date_sel>
	>     >     >></dates>
	>     >     >>
	>     >     >>
	>     >     >>
	>     >     >>TIA
	>     >     >>Luís Góis
	>     >     >
	>     >     >
	>     >     >
	>     >     >
	>     >     >
	>     >     > _______________________________________________________
	>     >     > Vizzavi Mail powered by Vodafone - http://www.vizzavi.pt
	>     >     > Virus protected by TrendMicro - http://www.antivirus.com
	>     >     >
	>     >     >
	>     >   
	>     ---------------------------------------------------------------------
	>     >     > Please check that your question  has not already been answered
	>     >     in the
	>     >     > FAQ before posting.  
	>     >     <http://xml.apache.org/cocoon/faq/index.html>
	>     >     >
	>     >     > To unsubscribe, e-mail:  
	>     >     <cocoon-users-unsubscribe@xml.apache.org>
	>     >     > For additional commands, e-mail:
	>     >     <cocoon-users-help@xml.apache.org>
	>     >     >
	>     >     >
	>     >
	>     >
	>
	>
	
	
	


Mime
View raw message