You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Kralidis,Tom [Burlington]" <To...@ec.gc.ca> on 2005/05/26 15:37:24 UTC
join and arrays
Hi,
I have a JSP which parses an XML document and inserts records into a DB.
For multiple XML elements, I do the following:
<sql:transaction dataSource="${ds_devgeodb}">
<sql:update>
insert into service_endpoints (keywords) values
('<x:forEach
select="$doc/WMT_MS_Capabilities/Service/KeywordList/Keyword"
var="kw"><x:out select="text()"/>,</x:forEach>')
</sql:update>
</sql:transaction>
Which works okay, except that the values in the DB end up as:
keyword1,keyword2,keyword3,
..whereas I would prefer
keyword1,keyword2,keyword3
(i.e. without the trailing comma)
I checked the fn:join() function, which looks like it would do the
trick, but how does one set an array in JSTL?
Any advice would be appreciated.
Thanks
..Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: join and arrays
Posted by Rahul P Akolkar <ak...@us.ibm.com>.
Lookup the varStatus attribute of <x:forEach>, it will allow you to query
for boundary cases (first/last) amongst other things and you can use that
to decide when the trailing delimiter is not needed (for the last
iteration of the forEach).
-Rahul
On 5/26/05, Kralidis,Tom [Burlington] <To...@ec.gc.ca> wrote:
>
> Hi,
>
> I have a JSP which parses an XML document and inserts records into a DB.
>
> For multiple XML elements, I do the following:
>
> <sql:transaction dataSource="${ds_devgeodb}">
> <sql:update>
> insert into service_endpoints (keywords) values
> ('<x:forEach
> select="$doc/WMT_MS_Capabilities/Service/KeywordList/Keyword"
> var="kw"><x:out select="text()"/>,</x:forEach>')
> </sql:update>
> </sql:transaction>
>
> Which works okay, except that the values in the DB end up as:
>
> keyword1,keyword2,keyword3,
>
> ..whereas I would prefer
>
> keyword1,keyword2,keyword3
>
> (i.e. without the trailing comma)
>
> I checked the fn:join() function, which looks like it would do the
> trick, but how does one set an array in JSTL?
>
> Any advice would be appreciated.
>
> Thanks
>
> ..Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>