Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Re: Obtaing Value
Re: Obtaing Value [message #42072] Thu, 21 February 2008 12:55 Go to next message
Eclipse UserFriend
Originally posted by:


Is this a question about JET? It's best to ask on the M2T newsgroup
about it. I've added it to the "to" list of this reply so Paul should
see it.

Raphael wrote:
> Hello my friends,
> I have the following XMI code:
> <?xml version="1.0" encoding="UTF-8"?>
> <Package xmi:version="2.1"
> xmlns:xmi=""
> xmi:id="_L37e0NiWEdyDI-twlSn5BQ" >
> <ownedMember xmi:type="uml20:Classe" xmi:id="_NsTmgNiWEdyDI-twlSn5BQ"
> name="People" package="_L37e0NiWEdyDI-twlSn5BQ">
> </ownedMember>
> </Package>
> When I use the command <c:get select="Package/ownedMember/@name" /> I
> got the result: People
> But, IŽm trying to obtain the xmi:id from ownedMember. IŽm using the
> following command <c:get select="Package/ownedMember/@xmi:id" /> , but
> this return no value.
> Has anyone here know what command should I use?!?
> Thanks,
> Raphael
Re: Obtaing Value [message #42165 is a reply to message #42072] Fri, 22 February 2008 14:03 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member

You'll have to implement a custom XPath function to get the XMI ID - the
XPath engine doesn't know how to extract this directly, and the ID is not
reflected in the EMF-metadata.

The function is pretty simple. Here's its implementation:

/*********************************************************** ********************
* Copyright (c) 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* Contributors:
* IBM - Initial API and implementation
* /
************************************************************ *******************/package org.eclipse.jet.examples.functions;import java.util.List;import org.eclipse.emf.ecore.EObject;import org.eclipse.emf.ecore.resource.Resource;import org.eclipse.emf.ecore.util.EcoreUtil;import org.eclipse.jet.xpath.NodeSet;import org.eclipse.jet.xpath.XPathFunction;/** * XPath function implementation that returns the EObject ID of an EObject.For * non-eObjects, it returns the empty string * */public class EObjectIDFunction implements XPathFunction { /* (non-Javadoc) * @see org.eclipse.jet.xpath.XPathFunction#evaluate(java.util.List) */ public Object evaluate(List args) { Object object = null; final Object objectArg = args.get(0); if(objectArg instanceof NodeSet) { NodeSet nodeSet = (NodeSet) objectArg; object = nodeSet.size() > 0 ? nodeSet.iterator().next() : null; } else { object = objectArg; } if(object instanceof EObject) { final EObject eObject = (EObject) object; final Resource resource = eObject.eResource(); return resource != null ? resource.getURIFragment(eObject) :EcoreUtil.getID(eObject); } else { return ""; } }}"Ed Merks" <> wrote in messagenews:fpjsd6$crl$> Raphael,>> Is this a question about JET? It's best to ask on the M2T newsgroup aboutit. I've added it to the "to" list of this reply so Paul should see it.>>> Raphael wrote:>> Hello my friends,>>>> I have the following XMI code:>>>> <?xml version="1.0" encoding="UTF-8"?>>> <Package xmi:version="2.1" xmlns:xmi=""xmi:id="_L37e0NiWEdyDI-twlSn5BQ" >>> <ownedMember xmi:type="uml20:Classe" xmi:id="_NsTmgNiWEdyDI-twlSn5BQ"name="People" package="_L37e0NiWEdyDI-twlSn5BQ">>> </ownedMember>>> </Package>>>>> When I use the command <c:get select="Package/ownedMember/@name" /> I gotthe result: People>>>> But, I
Previous Topic:model instance retrieval with ref to schema?
Next Topic:Issue with JMerge
Goto Forum:

Current Time: Mon Jun 18 05:56:45 GMT 2018

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

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

Back to the top