Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Accessing set variable in Java as String
Accessing set variable in Java as String [message #44575] Thu, 24 April 2008 18:12 Go to next message
Jeffrey Ricker is currently offline Jeffrey RickerFriend
Messages: 18
Registered: July 2009
Junior Member
My input looks like this:

<data>
<wrap>
<in package="com.foo" name="Foo"/>
<out project="my.proj" package="com.bar" name="Foo"/>
</wrap>
...
</data>

Here is my template fragment:

<c:iterate select="/data/wrap" var="wrap">
<c:setVariable var="interfaceName" select="$wrap/in/@name"/>
<%
String interfaceName = (String)context.getVariable("interfaceName");
%>
</c:iterate>

When I try to run this code I get a casting exception. It is returning a
NodeSetImpl rather than a String.
Re: Accessing set variable in Java as String [message #44613 is a reply to message #44575] Fri, 25 April 2008 01:50 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Try:

<c:setVariable var="interfaceName" select="string($wrap/in/@name)"/>

XPath expressions like $wrap/in/@name don't actually return strings, they
return 'nodes' in the input model. Most of the time, JET converts these to
strings for you.

Paul


"Jeffrey Ricker" <ricker@jeffreyricker.com> wrote in message
news:fuqii3$u8r$1@build.eclipse.org...
> My input looks like this:
>
> <data>
> <wrap>
> <in package="com.foo" name="Foo"/>
> <out project="my.proj" package="com.bar" name="Foo"/>
> </wrap>
> ...
> </data>
>
> Here is my template fragment:
>
> <c:iterate select="/data/wrap" var="wrap">
> <c:setVariable var="interfaceName" select="$wrap/in/@name"/>
> <%
> String interfaceName = (String)context.getVariable("interfaceName");
> %>
> </c:iterate>
>
> When I try to run this code I get a casting exception. It is returning a
> NodeSetImpl rather than a String.
>
Previous Topic:Problem with update site
Next Topic:does an eclipse project clean delete the jet2java sources ?
Goto Forum:
  


Current Time: Wed Nov 26 11:37:25 GMT 2014

Powered by FUDForum. Page generated in 0.06232 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software