Re: foreach with XMLTool

Ralph Goers <[email protected]> Wed, 2 Oct 2013 13:35:22 -0700
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
I suspect the solution is going to require changing get() to do


        if (s.indexOf('/') < 0)
        {
            s = "./" + s;
        }

instead of 

        if (s.indexOf('/') < 0)
        {
            s = getPath()+'/'+s;
        }

I'm not sure why it makes sense to have get always start at the root instead of at the current node.

Ralph

On Oct 2, 2013, at 11:23 AM, Nathan Bubna <[email protected]> wrote:

> Hmm. Sounds less than ideal. I don't have time to improve how the
> XMLTool handles this, but if you're up for filing a bug and perhaps
> even contributing a patch, that'd be great. :)
> 
> On Wed, Oct 2, 2013 at 11:05 AM, Ralph Goers <[email protected]> wrote:
>> I found that the problem isn't in the foreach.  It is that when you do
>> 
>> #foreach($row in $xml.details.row)
>>   $row.item1
>> #end
>> 
>> It results in item1 printing the item1 value for all rows.  This is because get() calls find("item1") which then calls node.selectNodes() in dom4j.  dom4j returns all the the nodes.  The only way I have found to fix this is to do
>> 
>>   $row.find("./item1")
>> 
>> This returns the value for only the current row.
>> 
>> Ralph
>> 
>> 
>> On Oct 2, 2013, at 8:21 AM, Ralph Goers <[email protected]> wrote:
>> 
>>> I have an XML document of the form
>>> 
>>> <data>
>>> <details>
>>>   <row>
>>>     <item1>
>>>     <item2>
>>>   </row>
>>>   <row>
>>>     <item1>
>>>     <item2>
>>>   </row>
>>> </details>
>>> </data>
>>> 
>>> I cannot seem to find a way to successfully iterate over the row elements.  For some reason the data from each of the rows is being co-mingled.  Does anyone have an example of iterating over xml elements using the XMLTool?
>>> 
>>> Ralph
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>