Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Is it possible to retrieve attributes and references from JET using XPath?
Is it possible to retrieve attributes and references from JET using XPath? [message #44077] Tue, 15 April 2008 19:12 Go to next message
Roshan S. is currently offline Roshan S.Friend
Messages: 125
Registered: July 2009
Senior Member
Hi,

I am trying to iterate through the list of attributes from my eCore. Say
I had my Book EObject. is there some way through some xpath functions to
list all of the attribute names, typename. I also want to do the same for
references.

So I want to do something like this:

My Model:

Book-Attributes= "name", "pageNum"
-Reference= "Author"

Author-Attributes= "name"

In JET I'd like to print out information about my model.
This doesn't work, but I think it explains what I'm trying to do.
The variable $Book is actually passed into the transformation as the
EClass object.

<c:iterate select="$Book/EAllAttributes" var="$EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>
<c:iterate select="$Book/EAllAttributes" var="$EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>

I can do this using Java or maybe create a custom XPath function/JETtag,
but it'd be cleaner and less work if I could use the XPath functions
included with JET.
Re: Is it possible to retrieve attributes and references from JET using XPath? [message #44108 is a reply to message #44077] Wed, 16 April 2008 06:38 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Roshan Soni wrote:

> <c:iterate select="$Book/EAllAttributes" var="$EAtt" >
> <c:get select="$EAtt/@name" />
> </c:iterate>
> <c:iterate select="$Book/EAllAttributes" var="$EAtt" >
> <c:get select="$EAtt/@name" />
> </c:iterate>

Hey, i think you can get ALL attributes in XPath with the wildcard
notation. I would try the following:

<c:iterate select="$Book/@*" var="att">
....
Re: Is it possible to retrieve attributes and references from JET using XPath? [message #44167 is a reply to message #44077] Wed, 16 April 2008 13:15 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Roshan:

JETs XPath engine can see any EReference or EAttribute feature implemented
by an EObject's EClass. Since $Book is an EClass instance, its EClass is
EClass itself. Looking at Javadoc for EClass gives you a hint to the
available features:

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/references/javadoc/org/eclipse/emf/ecore/EClass.html

A representation of the model object 'EClass'.

The following features are supported:

a.. Abstract
b.. Interface
c.. ESuper Types
d.. EOperations
e.. EAll Attributes
f.. EAll References
g.. EReferences
h.. EAttributes
i.. EAll Containments
j.. EAll Operations
k.. EAll Structural Features
l.. EAll Super Types
m.. EID Attribute
n.. EStructural Features
o.. EGeneric Super Types
p.. EAll Generic Super Types
(Plus all the features defined on super classes).

The trick is getting the right name for use in the XPath expressions. The
names listed above are not valid Java or XML names. EMF goes through a name
mangling process to arrive at the feature name that JET can actually see.
This is done by removing all spaces, and making the first letter lower case.
So, for EALL Attributes, you get eAllAttributes. A handy way to find the
names is to look at the implementation class (EClassImpl, in this case), and
use the field names for these features.

Next, if the feature is an EAttribute, you have to add an @ in front of the
name.

So, you code should be:

<c:iterate select="$Book/eAllAttributes" var="$EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>
<c:iterate select="$Book/eAllAttributes" var="$EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>

Paul

"Roshan Soni" <roshan.soni1@gmail.com> wrote in message
news:ab20266fb5d8d68abcd311720ca23a1c$1@www.eclipse.org...
> Hi,
>
> I am trying to iterate through the list of attributes from my eCore. Say
> I had my Book EObject. is there some way through some xpath functions to
> list all of the attribute names, typename. I also want to do the same for
> references.
> So I want to do something like this:
>
> My Model:
>
> Book-Attributes= "name", "pageNum"
> -Reference= "Author"
>
> Author-Attributes= "name"
>
> In JET I'd like to print out information about my model.
> This doesn't work, but I think it explains what I'm trying to do.
> The variable $Book is actually passed into the transformation as the
> EClass object.
>
> <c:iterate select="$Book/EAllAttributes" var="$EAtt" >
> <c:get select="$EAtt/@name" />
> </c:iterate>
> <c:iterate select="$Book/EAllAttributes" var="$EAtt" >
> <c:get select="$EAtt/@name" />
> </c:iterate>
>
> I can do this using Java or maybe create a custom XPath function/JETtag,
> but it'd be cleaner and less work if I could use the XPath functions
> included with JET.
>
Re: Is it possible to retrieve attributes and references from JET using XPath? [message #44417 is a reply to message #44167] Mon, 21 April 2008 15:08 Go to previous message
Roshan S. is currently offline Roshan S.Friend
Messages: 125
Registered: July 2009
Senior Member
Thanks Paul,

That's exactly what I needed. BTW, I made a typo in my initial post and
there should not be a '$' sign in the var attribute. So in the end this
is the code that worked.

<c:iterate select="$Book/eAllAttributes" var="EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>
<c:iterate select="$Book/eAllAttributes" var="EAtt" >
<c:get select="$EAtt/@name" />
</c:iterate>
Previous Topic:problem with 0.9.0 I200804162020
Next Topic:Problem with update site
Goto Forum:
  


Current Time: Wed Apr 24 23:03:16 GMT 2024

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

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

Back to the top