Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » JET - Only possible to use xpath?
JET - Only possible to use xpath? [message #16065] Thu, 17 May 2007 06:03 Go to next message
Apls Bsaim is currently offline Apls BsaimFriend
Messages: 8
Registered: July 2009
Junior Member

I have an XML file that I would use as input to my Jet file in order to read
the XML document and generate code.

It will be similar to the examples given here: ecl-jet/

To read an XML document from JET, is using xpath the only option?
I find xpath to be somewhat cumbersome and also I cannot get the square
brackets to work in JET.
For instance, if I say <c:get select="/AAA/BBB[1] " /> to "select the first
BBB child of element AAA" it doesn't do that.

Is there any way I can use scriptlets <% ... %> to get the nodes and
attributes from the XML model?
I think that might be easier for me as I am generating Java code.

Thanks for the help.
Re: JET - Only possible to use xpath? [message #16082 is a reply to message #16065] Thu, 17 May 2007 12:26 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
First, I'd like more details on this:

> For instance, if I say <c:get select="/AAA/BBB[1] " /> to "select the
> first BBB child of element AAA" it doesn't do that.

Can you send me an example? If it is not working, it is definitely a bug
that must be fixed.

As for using Java code, JET supports Java scriptlets, expressions and
declarations. Here's a link to the help page: jet.doc/references/syntax/jetSyntaxReference.xhtml

Some useful facts for writing Java code and accessing the transformation
source model:

1) The XPath expressions work on data stored in the JET2Context passed to
the template. In Java expressions and scriptlets, this is available as the
variable 'context'.
2) The root of the source document passed to the JET (which the XPath engine
treats as /) may be obtained by context.getSource().
3) The XPath variables are stored in the context, too:
context.getVariable(""). Do not include the dollar ($) sign.
4) The tricky part in writing some Java code is determining Java types
variables. JET loads XML documents using EMF's generic XML support.
Documents that have no XML Schema get loaded using the inscrutable AnyType.
If you have to write Java expressions against AnyType, I can guarantee
you'll have more code than an XPath expression.
5) If you transformation is reading a document that has a registered Ecore
model, then context.getSource() will be the EMF Resource object, and values
returned XPath expressions will be the EObjects in your model. It is much
easier to use Java expressions with such models.

Previous Topic:[ATL] problems to reference remote rules
Next Topic:Last time thru iterate?
Goto Forum:

Current Time: Tue Nov 29 22:30:09 GMT 2022

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

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

Back to the top