Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Getting a variable which name is the content of another.
Getting a variable which name is the content of another. [message #37912] Wed, 12 December 2007 19:07 Go to next message
Juan Pedro Silva is currently offline Juan Pedro SilvaFriend
Messages: 258
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi everybody.<br>
I'm a little stuck trying to do something I new how, but suddenly
completely forgot about it.<br>
Let see if I can explain myself.<br>
<br>
I launch my Jet transformation from java code, and while launching it,
I provide a Map with several variables.<br>
Among them, I set:<br>
<br>
<table border="1" cellpadding="2" cellspacing="2" height="60"
width="1032">
<tbody>
<tr>
<td valign="top">packageName<br>
</td>
<td valign="top">schemaLocation<br>
</td>
</tr>
<tr>
<td valign="top">schemaLocation</td>
<td valign="top">nameSpaceURI<br>
</td>
</tr>
</tbody>
</table>
<br>
Then, from within my template, I have the package name, and need to get
the other two values.<br>
I unsuccessfully tried:&nbsp; &lt;c:setVariable select="{$paquetes/@name}"
var="schemaLocation"/&gt; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;c:setVariable
select="{$schemaLocation}" var="nameSpaceURI"/&gt; <br>
<br>
I also tried:<br>
&lt;c:setVariable select="string($paquetes/@name)" var="nombre"/&gt;<br>
&lt;% if(context.hasVariable("nombre"))<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nombreActual =
(String)context.getVariable("nombre");&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String slActual =
(String)context.getVariable(nombreActual);&nbsp;&nbs p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("slActual", slActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nsActual =
(String)context.getVariable(slActual);&nbsp;&nbsp;&a mp;nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("nsActual", nsActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("nombreActual: " +
nombreActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("slActual: " + slActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("nsActual: " + nsActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
%&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
For this last code I get some sort of cast exception, I believe, when
trying to access the variables set in the map as "String" elements.<br>
Any hints?, I'm so frustrated because I KNOW I did this before.<br>
<br>
Thanks in advance,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Juan Pedro<br>
</body>
</html>
Re: Getting a variable which name is the content of another. [message #37945 is a reply to message #37912] Thu, 13 December 2007 11:13 Go to previous messageGo to next message
Juan Pedro Silva is currently offline Juan Pedro SilvaFriend
Messages: 258
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Just to clarify, the map is:<br>
<br>
<table border="1" cellpadding="2" cellspacing="2" height="88"
width="1046">
<tbody>
<tr>
<td align="center" valign="top"><b>KEY<br>
</b></td>
<td align="center" valign="top"><b>VALUE<br>
</b></td>
</tr>
<tr>
<td valign="top">packageName<br>
</td>
<td valign="top">schemaLocation<br>
</td>
</tr>
<tr>
<td valign="top">schemaLocation</td>
<td valign="top">nameSpaceURI<br>
</td>
</tr>
</tbody>
</table>
<br>
Thanks,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Juan Pedro<br>
<br>
Juan Pedro Silva escribi&oacute;:
<blockquote cite="mid:fjpbhh$9ps$1@build.eclipse.org" type="cite">Hi
everybody.<br>
I'm a little stuck trying to do something I new how, but suddenly
completely forgot about it.<br>
Let see if I can explain myself.<br>
<br>
I launch my Jet transformation from java code, and while launching it,
I provide a Map with several variables.<br>
Among them, I set:<br>
<br>
<table border="1" cellpadding="2" cellspacing="2" height="60"
width="1032">
<tbody>
<tr>
<td valign="top">packageName<br>
</td>
<td valign="top">schemaLocation<br>
</td>
</tr>
<tr>
<td valign="top">schemaLocation</td>
<td valign="top">nameSpaceURI<br>
</td>
</tr>
</tbody>
</table>
<br>
Then, from within my template, I have the package name, and need to get
the other two values.<br>
I unsuccessfully tried:&nbsp; &lt;c:setVariable select="{$paquetes/@name}"
var="schemaLocation"/&gt; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;c:setVariable
select="{$schemaLocation}" var="nameSpaceURI"/&gt; <br>
<br>
I also tried:<br>
&lt;c:setVariable select="string($paquetes/@name)" var="nombre"/&gt;<br>
&lt;% if(context.hasVariable("nombre"))<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nombreActual =
(String)context.getVariable("nombre");&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String slActual =
(String)context.getVariable(nombreActual);&nbsp;&nbs p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("slActual", slActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nsActual =
(String)context.getVariable(slActual);&nbsp;&nbsp;&a mp;nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("nsActual", nsActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("nombreActual: " +
nombreActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("slActual: " + slActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("nsActual: " + nsActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
%&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
For this last code I get some sort of cast exception, I believe, when
trying to access the variables set in the map as "String" elements.<br>
Any hints?, I'm so frustrated because I KNOW I did this before.<br>
<br>
Thanks in advance,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Juan Pedro<br>
</blockquote>
</body>
</html>
Re: Getting a variable which name is the content of another. [message #37979 is a reply to message #37912] Thu, 13 December 2007 14:10 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C83D67.F673F720
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Jaun Pedro:

From you messages, I'm guessing that one JET variable contains the name =
of the other, and you are trying to resolve the indirect reference.

So, given that you know $packageName contains a variable name (in this =
instance 'schemaLocation'), how do you get the value of that variable?

The trick it to use 'dynamic' XPath expressions (XPath expresssions =
enclosed in { } ) in a select attribute. At runtime, dynamic expressions =
are resolved into string values prior to being passed to the tag =
handler. (Normally, XPath expressions in select and test attributes =
should not be surrounded by { and } ). Remember that a select attribute =
must contain a valid XPath expression AFTER any dynamic expressions have =
been resolved.

So, in your case, you want the XPath expression: $schemaLocation

But, the variable name 'schemaLocation' is the value of another =
variable, $packageName. So write: ${$packageName}

Example:

<c:get select=3D"${$packageName}"/>

will result in 'namespaceURI'

Note that the expansion of dynamic XPath expression is not recursive, so =
that trying to do another level in indirection in a single select =
attribute will not work. So:

c:get select=3D"${${$packageName}}"/>

would NOT return the value of the variable $nameSpaceURI. Instead, it =
will likely result in a XPath expression compilation error.

Hope this helps,

Paul
"Juan Pedro Silva" <jpsilvagallino@gmail.com> wrote in message =
news:fjpbhh$9ps$1@build.eclipse.org...
Hi everybody.
I'm a little stuck trying to do something I new how, but suddenly =
completely forgot about it.
Let see if I can explain myself.

I launch my Jet transformation from java code, and while launching it, =
I provide a Map with several variables.
Among them, I set:

packageName
schemaLocation
=20
schemaLocation nameSpaceURI
=20

Then, from within my template, I have the package name, and need to =
get the other two values.
I unsuccessfully tried: <c:setVariable select=3D"{$paquetes/@name}" =
var=3D"schemaLocation"/>=20
<c:setVariable =
select=3D"{$schemaLocation}" var=3D"nameSpaceURI"/>=20

I also tried:
<c:setVariable select=3D"string($paquetes/@name)" var=3D"nombre"/>
<% if(context.hasVariable("nombre"))
{ =20
String nombreActual =3D =
(String)context.getVariable("nombre"); =20
String slActual =3D =
(String)context.getVariable(nombreActual); =20
context.setVariable("slActual", slActual);
String nsActual =3D =
(String)context.getVariable(slActual); =20
context.setVariable("nsActual", nsActual); =
=20
System.out.println("nombreActual: " + =
nombreActual); =20
System.out.println("slActual: " + slActual);
System.out.println("nsActual: " + nsActual);
}
%> =20

For this last code I get some sort of cast exception, I believe, when =
trying to access the variables set in the map as "String" elements.
Any hints?, I'm so frustrated because I KNOW I did this before.

Thanks in advance,
Juan Pedro

------=_NextPart_000_000E_01C83D67.F673F720
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.3199" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Jaun Pedro:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>From you messages, I'm guessing that =
one JET=20
variable contains the name of the other, and you are trying to resolve =
the=20
indirect reference.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So, given that you know $packageName =
contains a=20
variable name (in this instance 'schemaLocation'), how do you get the =
value of=20
that variable?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The trick it to use 'dynamic' XPath =
expressions=20
(XPath expresssions enclosed in { } ) in a select attribute. At runtime, =
dynamic=20
expressions are resolved into string values prior to being passed to the =
tag=20
handler. (Normally, XPath expressions in select and test attributes =
should not=20
be surrounded by { and } ). Remember that a select attribute must =
contain a=20
valid XPath expression AFTER any dynamic expressions have been=20
resolved.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So, in your case, you want&nbsp;the =
XPath=20
expression: $schemaLocation</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But, the variable name 'schemaLocation' =
is&nbsp;the=20
value&nbsp;of another variable, $packageName. So write:=20
${$packageName}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Example:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&lt;c:get=20
select=3D"${$packageName}"/&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>will result in =
'namespaceURI'</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Note that the expansion of dynamic =
XPath expression=20
is not recursive, so that trying to do another level in indirection in a =
single=20
select attribute will not work. So:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>c:get =
select=3D"${${$packageName}}"/&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>would&nbsp;NOT return the value of the =
variable=20
$nameSpaceURI. Instead, it will likely result in a XPath expression =
compilation=20
error.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Hope this helps,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Paul</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Juan Pedro Silva" &lt;<A=20
=
href=3D"mailto:jpsilvagallino@gmail.com">jpsilvagallino@gmail.com</A>&gt;=
wrote=20
in message <A=20
=
href=3D"news:fjpbhh$9ps$1@build.eclipse.org">news:fjpbhh$9ps$1@build.ecli=
pse.org</A>...</DIV>Hi=20
everybody.<BR>I'm a little stuck trying to do something I new how, but =

suddenly completely forgot about it.<BR>Let see if I can explain=20
myself.<BR><BR>I launch my Jet transformation from java code, and =
while=20
launching it, I provide a Map with several variables.<BR>Among them, I =

set:<BR><BR>
<TABLE height=3D60 cellSpacing=3D2 cellPadding=3D2 width=3D1032 =
border=3D1>
<TBODY>
<TR>
<TD vAlign=3Dtop>packageName<BR></TD>
<TD vAlign=3Dtop>schemaLocation<BR></TD></TR>
<TR>
<TD vAlign=3Dtop>schemaLocation</TD>
<TD =
vAlign=3Dtop>nameSpaceURI<BR></TD></TR></TBODY></TABLE ><BR>Then, from =
within=20
my template, I have the package name, and need to get the other two=20
values.<BR>I unsuccessfully tried:&nbsp; &lt;c:setVariable=20
select=3D"{$paquetes/@name}" var=3D"schemaLocation"/&gt; =
<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
&lt;c:setVariable select=3D"{$schemaLocation}" =
var=3D"nameSpaceURI"/&gt; <BR><BR>I=20
also tried:<BR>&lt;c:setVariable select=3D"string($paquetes/@name)"=20
var=3D"nombre"/&gt;<BR>&lt;%=20
if(context.hasVariable("nombre"))<BR>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String =
nombreActual =3D=20
(String)context.getVariable("nombre");&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String =
slActual =3D=20
(String)context.getVariable(nombreActual);&nbsp;&nbs p;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
context.setVariable("slActual", slActual);<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
String nsActual =3D =
(String)context.getVariable(slActual);&nbsp;&nbsp;&a mp;nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("nsActual",=20
nsActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
System.out.println("nombreActual: " +=20
nombreActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
System.out.println("slActual: " + slActual);<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
System.out.println("nsActual: " + nsActual);<BR>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
}<BR>%&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <BR><BR>For =
this last=20
code I get some sort of cast exception, I believe, when trying to =
access the=20
variables set in the map as "String" elements.<BR>Any hints?, I'm so=20
frustrated because I KNOW I did this before.<BR><BR>Thanks in=20
=
advance,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;=20
Juan Pedro<BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000E_01C83D67.F673F720--
Re: Getting a variable which name is the content of another. [message #38009 is a reply to message #37979] Thu, 13 December 2007 15:11 Go to previous message
Juan Pedro Silva is currently offline Juan Pedro SilvaFriend
Messages: 258
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Excelent Paul, thanks for your help. <br>
I will give this a try as soon as I get my eclipse back on track
(suddenly stop working as expected).<br>
Regards,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; Juan Pedro<br>
<br>
Paul Elder escribi&oacute;:
<blockquote cite="mid:fjreii$oc3$1@build.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta content="MSHTML 6.00.2900.3199" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">Jaun Pedro:</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">From you messages, I'm guessing that
one JET variable contains the name of the other, and you are trying to
resolve the indirect reference.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">So, given that you know $packageName
contains a variable name (in this instance 'schemaLocation'), how do
you get the value of that variable?</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">The trick it to use 'dynamic' XPath
expressions (XPath expresssions enclosed in { } ) in a select
attribute. At runtime, dynamic expressions are resolved into string
values prior to being passed to the tag handler. (Normally, XPath
expressions in select and test attributes should not be surrounded by {
and } ). Remember that a select attribute must contain a valid XPath
expression AFTER any dynamic expressions have been resolved.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">So, in your case, you want&nbsp;the XPath
expression: $schemaLocation</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">But, the variable name
'schemaLocation' is&nbsp;the value&nbsp;of another variable, $packageName. So
write: ${$packageName}</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Example:</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">&lt;c:get
select="${$packageName}"/&gt;</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">will result in 'namespaceURI'</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Note that the expansion of dynamic
XPath expression is not recursive, so that trying to do another level
in indirection in a single select attribute will not work. So:</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">c:get
select="${${$packageName}}"/&gt;</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">would&nbsp;NOT return the value of the
variable $nameSpaceURI. Instead, it will likely result in a XPath
expression compilation error.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Hope this helps,</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Paul</font></div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div>"Juan Pedro Silva" &lt;<a moz-do-not-send="true"
href="mailto:jpsilvagallino@gmail.com">jpsilvagallino@gmail.com</a>&gt;
wrote in message <a moz-do-not-send="true"
href="news:fjpbhh$9ps$1@build.eclipse.org">news:fjpbhh$9ps$1@build.eclipse.org</a>...</div>
Hi everybody.<br>
I'm a little stuck trying to do something I new how, but suddenly
completely forgot about it.<br>
Let see if I can explain myself.<br>
<br>
I launch my Jet transformation from java code, and while launching it,
I provide a Map with several variables.<br>
Among them, I set:<br>
<br>
<table border="1" cellpadding="2" cellspacing="2" height="60"
width="1032">
<tbody>
<tr>
<td valign="top">packageName<br>
</td>
<td valign="top">schemaLocation<br>
</td>
</tr>
<tr>
<td valign="top">schemaLocation</td>
<td valign="top">nameSpaceURI<br>
</td>
</tr>
</tbody>
</table>
<br>
Then, from within my template, I have the package name, and need to get
the other two values.<br>
I unsuccessfully tried:&nbsp; &lt;c:setVariable select="{$paquetes/@name}"
var="schemaLocation"/&gt; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;c:setVariable
select="{$schemaLocation}" var="nameSpaceURI"/&gt; <br>
<br>
I also tried:<br>
&lt;c:setVariable select="string($paquetes/@name)" var="nombre"/&gt;<br>
&lt;% if(context.hasVariable("nombre"))<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nombreActual =
(String)context.getVariable("nombre");&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String slActual =
(String)context.getVariable(nombreActual);&nbsp;&nbs p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("slActual", slActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String nsActual =
(String)context.getVariable(slActual);&nbsp;&nbsp;&a mp;nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; context.setVariable("nsActual", nsActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("nombreActual: " +
nombreActual);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("slActual: " + slActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("nsActual: " + nsActual);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
%&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
For this last code I get some sort of cast exception, I believe, when
trying to access the variables set in the map as "String" elements.<br>
Any hints?, I'm so frustrated because I KNOW I did this before.<br>
<br>
Thanks in advance,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Juan Pedro<br>
</blockquote>
</blockquote>
</body>
</html>
Previous Topic:selecting the "highest version" of an xml element for a jet2 transform
Next Topic:[JET2] setVariable question
Goto Forum:
  


Current Time: Fri Apr 26 23:44:36 GMT 2024

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

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

Back to the top