cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker Template Process XML Document

parrym
Champ in-the-making
Champ in-the-making
I am having trouble processing an XML document with a Freemarker template within a Web Script. I have given a stripped down example below:

getContent.get.js
var doc1 = userhome.createFile("transform_me4.txt");
doc1.mimetype = "text/xml";
doc1.content = "<category><article>see me</article></category>";
doc1.save;
var temp1 = "<h3>Can you ${category.article}</h3>";
var result = doc1.processTemplate(temp1);
model.result = result;

getContent.get.html.ftl
${result}

Message:   07260344 Wrapped Exception (with status template): 07260343 Failed to execute script '/schema/getContent.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts)': 07260342 Error during processing of the template 'Expression category is undefined on line 1, column 15 in string://fixed.'. Please contact your system administrator.
   
Exception:   freemarker.core.InvalidReferenceException - Expression category is undefined on line 1, column 15 in string://fixed.

I also have a problem including
<#assign doc = alf.parseXMLDocument(article.include_portal)>
as alf is undefined.

My xml file and ftl template work in a web form, is there a way to emulate that with a webscript?
1 REPLY 1

parrym
Champ in-the-making
Champ in-the-making
After studying other posts and a lot of google and alfresco wiki I have made a little bit of progress. Instead of using processTemplate I have made my getContent.get.html.ftl the template and prefixed all my variables with xml_doc. I have also edited my content.get.js to pass the xml content node to the template:

getContent.get.js

var node = avm.lookupNode(args['from']);
var result = node;

getContent.get.html.ftl

<#assign xml_doc=node.xmlNodeModel>

My only problem now is alf.parseXMLDocument doesn't work. Do i need to add something to the ns_prefixes or is there a certain way to load the alf. commands?

07270352 Wrapped Exception (with status template): 07270351 Error during processing of the template 'Expression alf is undefined on line 3, column 16 in schema/getContent.get.html.ftl.'. Please contact your system administrator.