Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] How to iterate elements to find the value, corresponding to a certain name?
[ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557322] Mon, 06 September 2010 16:49 Go to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hello!

In my transformation I need to get the value of the attribute "version" (which is =1):

rule  DocumentRootElement {
	from
		s	:	XML!Root (s.name = 'History')
	to
				t	: 	Garmin!DocumentRoot(
			....... some other transformations...... )
			,
			
			t2	:	Garmin!HistoryType
                        (
			
			version <-s.getValue('Version')

                         )


The helper "getValue()" looks like that:


helper context XML!Element def: getValue(name : String) : String= 
let a: Sequence(XML!Element) = self->select(c | c.name = name) in
if a.isEmpty() then 'no_value'
else 
a.first().children->first().value
endif;


The part of the source-model, where the iteration has to be done (so, in other words, where the value for the name='version' has to be found) is here:

<Root xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="XML" startLine="1"
    startColumn="1" endLine="21489" endColumn="11" name="History">
  <children xsi:type="Attribute" name="xmlns" value="http://www.garmin.com/xmlschemas/ForerunnerLogbook"/>
  <children xsi:type="Attribute" name="xmlns:xsi" value="http://www.w3.org/2001/XMLSchema-instance"/>
  <children xsi:type="Attribute" name="xsi:schemaLocation" value="http://www.garmin.com/xmlschemas/ForerunnerLogbook http://www.garmin.com/xmlschemas/ForerunnerLogbookv1.xsd"/>
  <children xsi:type="Attribute"[B] [COLOR=blue]name="version" value="1"[/COLOR][/B]/>
  <children xsi:type="Text" startLine="3" startColumn="264" endLine="4" endColumn="6"
      name="#text" value="&#xD;&#xA;    "/>
  <children xsi:type="Element" startLine="4" startColumn="6" endLine="1310" endColumn="11"
      name="Run">


But it doesnt work!
ATL tells me this:

Quote:
org.eclipse.m2m.atl.engine.emfvm.VMException: Cannot iterate on IN!History
at getValue2#4(XML2Garmin.atl[295:33-295:64])
local variables: self=IN!History, name='Version'





What is wrong? Could someone please help me?
Thank you very much.

Alexey

[Updated on: Mon, 06 September 2010 17:19]

Report message to a moderator

Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557890 is a reply to message #557322] Thu, 09 September 2010 11:11 Go to previous messageGo to next message
Marcel  is currently offline Marcel Friend
Messages: 54
Registered: July 2009
Member
In your helper you use the following:
self->select
You pass the helper an element of type XML!Root.
As far as I can see, is XML!Root a single element and not a collection that you can iterate over using ->select().
Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557891 is a reply to message #557890] Thu, 09 September 2010 11:14 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Hi!

It may be very well so. Im not so good in ATL yet. I just want to pick up this version value with a helper. Could you please advise me, how to do that?

Alexey

[Updated on: Thu, 09 September 2010 11:15]

Report message to a moderator

Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557892 is a reply to message #557891] Thu, 09 September 2010 11:17 Go to previous messageGo to next message
Marcel  is currently offline Marcel Friend
Messages: 54
Registered: July 2009
Member
Judging from the XMI excerpt I think it should be something along the lines of:
self.children->select(c | c.name = name)
You should look in the metamodel to see which reference you should use.
Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557896 is a reply to message #557892] Thu, 09 September 2010 11:26 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
I'll try it now and tell you what has come!
Thanks!
Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557902 is a reply to message #557892] Thu, 09 September 2010 11:44 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Marcel wrote on Thu, 09 September 2010 07:17
Judging from the XMI excerpt I think it should be something along the lines of:
self.children->select(c | c.name = name)
You should look in the metamodel to see which reference you should use.


Now, I have this helper:
helper context XML!Element def: getValue2(name : String) : String= let a: Sequence(XML!Element) = self->select(c | c.name = name) in
if a.isEmpty() then 'no_value'
else 
a.first()->first().value
endif;


And this is the place I call it:

rule  DocumentRootElement {
	from
		s:XML!Root (s.name = 'History')
	to
	t: Garmin!DocumentRoot(

----some transformations---
						)
			,
			
	t2:Garmin!HistoryType(
		
version <-s.getValue2('Version')
					)
	}





But it doesnt work neither!

I get this err message:



org.eclipse.m2m.atl.engine.emfvm.VMException: Cannot iterate on IN!History at getValue2#4(XML2Garmin.atl[296:33-296:64]) local variables: self=IN!History, name='Version'
Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557914 is a reply to message #557322] Thu, 09 September 2010 12:10 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Do you have a special anger against the "children" reference or something ?
let a: Sequence(XML!Element) = self->select(c | c.name = name) in

self is an XML!Element, you can only use select on a sequence.

What you really want si to select the version attribute which is contained in the "children" reference of your XML!Element History.
So as Marcel wrote :
self.children->select(c | c.name = name)
Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557917 is a reply to message #557914] Thu, 09 September 2010 12:22 Go to previous messageGo to next message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member
Thank you very much, I try it now and tell what I achieved!
Re: [ATL] How to iterate elements to find the value, corresponding to a certain name? [message #557982 is a reply to message #557917] Thu, 09 September 2010 16:52 Go to previous message
Alexey is currently offline AlexeyFriend
Messages: 61
Registered: January 2010
Member

Do you mean it must look like this?

Quote:
helper context XML!Element def: getValue2(name : String) : String=
let a: Collection(XML!Element) = self.children->select(c | c.name = name) in
if a.isEmpty() then 'no_value'
else
a.first()->first().value
endif;

Previous Topic:[QVTo] Timing transformations
Next Topic:UML class diagram to JAVA code
Goto Forum:
  


Current Time: Thu Apr 18 10:36:54 GMT 2024

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

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

Back to the top