Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET] Running JET via Java Code only returns static contents of the template
[JET] Running JET via Java Code only returns static contents of the template [message #538152] Sat, 05 June 2010 15:13 Go to next message
Christian Kurze is currently offline Christian Kurze
Messages: 16
Registered: July 2009
Junior Member
Hi,

I try to run a JET transformation via Java Code as described here: http://wiki.eclipse.org/M2T-JET-FAQ/How_do_I_run_a_JET_templ ate_from_Java%3F

The transformaiton starts and outputs a String. My problem is that the passed org.w3c.dom.Document is not parsed. The JET tags c:get and c:iterate have no effect, just the "static" contents of my template are returned, but no information from the passed XML file is returned.

Has anybody any idea what I'm doing wrong?

My source code calling the template (curFile ist of type IFile):

Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(curFile.getContents());

final JET2Context jet2Context = JET2Helpers.createJETContext(doc, null);

final BufferedJET2Writer jet2Writer = JET2Helpers.createJETWriter();

try {
    JET2TemplateManager.run(new String[] {"myTransformation.jet"}, new JET2TemplateManager.ITemplateOperation() {
        public void run(ITemplateRunner templateRunner) {
            templateRunner.generate("templates/newCatalog2CSV.jet", jet2Context, jet2Writer);
        }
    });
    
    System.out.println(jet2Writer.getContent());
    
} catch (BundleException be) {
	MessageDialog.openError(shell, "Fehler", be.getMessage());
}


My JET is the following:
SUPPLIER_PID;SUPPLIER_IDREF;DESCRIPTION_SHORT;EAN;PRICE;PRICE_VALID_FROM;PRICE_VALID_TO
Version: <c:get select="/CAT/@version" />

<c:iterate select="//T_NEW_CATALOG" var="catalog">
<c:iterate select="$catalog/PRODUCT" var="product">
<c:get select="$product/SUPPLIER_PID" />;<c:get select="$product/SUPPLIER_IDREF" />;<c:get select="$product/PRODUCT_DETAILS/DESCRIPTION_SHORT" />;<c:get select="$product/PRODUCT_DETAILS/EAN" />;<c:get select="$product/PRODUCT_PRICE_DETAILS/PRODUCT_PRICE" />;<c:get select="$product/PRODUCT_PRICE_DETAILS/VALID_START_DATE" />;<c:get select="$product/PRODUCT_PRICE_DETAILS/VALID_END_DATE" />
</c:iterate>
</c:iterate>


The Document is read correctly, in the debugger I see all the tags. If I execute the transformation manually everything works fine. Just the first line as well as "Version" is included in the output String when running the template via Java Code.

I call a simple dump-template via code an everything looks fine. I cannot find my mistake. Why does a dump work, but a "real" template not?


Thanks in advance for any help.


Chris

[Updated on: Sun, 06 June 2010 04:23]

Report message to a moderator

Additional Info: [JET] Running JET via Java Code only returns static contents of the template [message #538194 is a reply to message #538152] Sun, 06 June 2010 05:38 Go to previous message
Christian Kurze is currently offline Christian Kurze
Messages: 16
Registered: July 2009
Junior Member
Hi,

my problem results of namespaces. I'm aware that JET is not able to select elements via namespaces. Nevertheless, the XPath processor should match expressions containing unqualified names with elements and attributes that include a namespace prefix. (See e.g. http://www.linuxtopia.org/online_books/eclipse_documentation /eclipse_jet_development_guide/topic/org.eclipse.jet.doc/tas ks/eclipse_jet_usingJetWithXML.html as well as http://dev.eclipse.org/newslists/news.eclipse.modeling.m2t/m sg00158.html).

My Source XML (excerpt):
<ns0:CAT xmlns:ns0="http://www.example.org/cat/2005fd" version="2005fd">
<ns0:HEADER>
...
</ns0:HEADER>
</ns0:CAT>


A simple output of the version attribute does not work via <c:get select="/CAT/@version" />
If I remove the namespace ns0 everything works fine. But there are 500 large XML files I do not want to change them prior transformation due to performance requirements.

Any more ideas? I don't know where to look for...

Thanks!

Chris

[Updated on: Sun, 06 June 2010 06:14]

Report message to a moderator

Previous Topic:Xtend/Xpand support in ohloh
Next Topic:[Acceleo] Properties
Goto Forum:
  


Current Time: Wed Jul 30 19:35:31 EDT 2014

Powered by FUDForum. Page generated in 0.04854 seconds