Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » JET: accessing JET variables from inline java
JET: accessing JET variables from inline java [message #55768] Tue, 20 January 2009 19:46 Go to next message
Eclipse UserFriend
Originally posted by: johannes.nel.gmail.com

Hi all

In a JET template is there a way for me to access xpath variables from
inline Java.

<c:setVariable var="path" select="getPathFromPackage($curItem/@package)"/>
<% System.out.println($path); %>


thanks johan
Re: accessing JET variables from inline java [message #55854 is a reply to message #55768] Wed, 21 January 2009 16:51 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Johan:

There is JET2Context.getVariable:

http://help.eclipse.org/ganymede/topic/org.eclipse.jet.doc/r eferences/javadoc/org/eclipse/jet/JET2Context.html#getVariab le(java.lang.String)

The variable 'context' is predefined in your template.

But, you may find that the type of the value returned is sometimes a
NodeSet (depending on the original expression). You can use use
XPathUtil.xpathString():

http://help.eclipse.org/ganymede/topic/org.eclipse.jet.doc/r eferences/javadoc/org/eclipse/jet/xpath/XPathUtil.html#xpath String(java.lang.Object)

It will convert the result to a String:
<%@jet imports="org.eclipse.jet.xpath.XPathUtil" %>
<%= System.out.println(XPathUtil.xpathString(context.getVariable ( "path")) %>

Finally, if all you are doing is trying to inject trace statements into your
transformation, why not try the <c:log> tag:

http://help.eclipse.org/ganymede/topic/org.eclipse.jet.doc/r eferences/taglibs/controlTags/logTag.html

<c:log><c:get select="$path"/></c:log>

The tag has an optional attribute that specifies the log level. By default,
an executing JET transformation writes only info, warning and error
messages. This can be changed in the JET launch configuration.

Paul
Previous Topic:character entity in the input model gets substituted in the generated file even if it's xml/xhtml
Next Topic:[MTL] UML primitive type problems
Goto Forum:
  


Current Time: Fri Apr 19 02:24:58 GMT 2024

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

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

Back to the top