velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Reck <apa...@recks.org>
Subject Re: To many iterations in DVSL foreach directive
Date Mon, 12 Jul 2004 14:11:01 GMT
Hi,

the iterator is also returning the text nodes (containing whitespaces).
So check that it is an element node before accessing $field.name().

Cheers,
Christoph

Soren Praestegaard wrote:
> Hi all!
> 
> I've made an example with DVSL, but my output is a little strange.
> 
> This XML file::
> ************************************
> <?xml version="1.0"?>
> <monkeylist>
>   <monkey>MONKEY_VALUE
>     <firstname>Monkey</firstname>
>     <lastname>Man</lastname>
>     <city>monkeytown</city>
>     <phone>12314567</phone>
>     <email>monkey@monkeysworld.mnk</email>
>     <password>password</password>
>     <comes>Friday</comes>
>     <leaves>Sunday</leaves>
>     <have_payed>no</have_payed>
>   </monkey>
> </monkeylist>
> **********************************
> 
> is merged with this DVSL template:
> ***************************************
> #match("monkey")
> <html>
>   <body>  
>   #foreach ( $field in $node.children() )
>     <br>
>     $velocityCount
>     $field.name()
>     $field.value()
>   #end
>   </body>
> </html>
> #end
> ************************************
> 
> It all takes place in a servlet with this code segment:
> ***********************************************
> PrintWriter out = resp.getWriter();
> DVSL dvsl = new DVSL();
> Reader in = new InputStreamReader(System.in);    
> dvsl.setStylesheet("e:/xdocs/example1.dvsl");
> in = new FileReader("e:/xdocs/example1.xml");
> dvsl.transform(in, out);
> out.flush();
> *****************************************
> 
> The HTML output is:
> ***********************************************
> <BODY><BR>1 $field.name() MONKEY_VALUE <BR>2 $field.name() <BR>3
> $field.name() 
> <BR>4 firstname Monkey <BR>5 $field.name() <BR>6 $field.name() <BR>7
> lastname 
> Man <BR>8 $field.name() <BR>9 $field.name() <BR>10 city monkeytown
> <BR>11 
> $field.name() <BR>12 $field.name() <BR>13 phone 12314567 <BR>14
> $field.name() 
> <BR>15 $field.name() <BR>16 email monkey@monkeysorld.dk <BR>17
> $field.name() 
> <BR>18 $field.name() <BR>19 password password <BR>20 $field.name()
> <BR>21 
> $field.name() <BR>22 comes Friday <BR>23 $field.name() <BR>24
> $field.name() 
> <BR>25 leaves Sunday <BR>26 $field.name() <BR>27 $field.name() <BR>28
> have_payed 
> no <BR>29 $field.name() <BR>30 $field.name() </BODY></HTML>
> ***********************************************
> 
> As you can see, there is to many iterations, and the $field.name()
> statement can't be resolved in 2/3 og the iterations.
> 
> If i remove "prettyt print" from the XML file, so the whole file is in
> one single line, the output gets a little better:
> ************************************************
> <BODY><BR>1 $field.name() MONKEY_VALUE <BR>2 firstname Monkey <BR>3
> lastname Man 
> <BR>4 city monkeytown <BR>5 phone 12314567 <BR>6 email
> monkey@monkeysorld.dk 
> <BR>7 password password <BR>8 comes Friday <BR>9 leaves Sunday <BR>10
> have_payed 
> no </BODY></HTML>
> *************************************************
> 
> I can get around the many iterations by altering the DVSL source code,
> by configuring the XML reader in DVSL so that it ignores whit spaces,
> but it shouldn't really be necessary to alter the source code to get it
> to work right. 
> If I run the example with the Ant build.xml provided with the DVSL
> distribution, it works fine, so why can't I get it right merging from a
> servlet?
> 
> Another, even bigger, problem in the above example, is that the text
> content of the "monkey" element is being treated as a child. The content
> of the "monkey" element (MONKEY_VALUE) is printet out to the output.
> This is happening both via the provided Ant build and the servletcode.
> It's probably a template problem, cause I'm new to Velocity and DVSL.
> 
> Any suggestions?
> 
> Thank's Soeren Praestegaard 
> 
> 
> ----------------------------------------
> Min mail er beskyttet af SPAMfighter
> 2061 spam mails er blokeret indtil videre.
> Hent gratis www.spamfighter.dk i dag!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message