cancel
Showing results for 
Search instead for 
Did you mean: 

Rendition Service - xsltRenderingEngine - template path

nick_vermeulen
Champ in-the-making
Champ in-the-making
I am trying pass the xsltRenderingEngine a template path as set out here http://wiki.alfresco.com/wiki/XSLT_rendering_engine

PARAM_TEMPLATE_PATH: (String) the path to the node whose cm:content property contains the XSLT. The display path is used for this parameter. That is to say "/Company Home/…" as opposed to "/app:company_home/…".

The Java Script is as follows:

// Setup the rendition name and engine
var ixbrlRendtionName = "cm:ixbrlRendition";
var ixbrlRenderingEngine = "xsltRenderingEngine";

var ixbrlRenditionDef = renditionService.createRenditionDefinition(ixbrlRendtionName , ixbrlRenderingEngine);

// Set the parameters
ixbrlRenditionDef.parameters['template_path'] = "/Company Home/Data Dictionary/Rendering Actions Space/prepare-input.xsl";

// Execute Rendition
var rendition = renditionService.render(document, ixbrlRenditionDef);

This results in the following error when running the script.

Please correct the errors below then click OK.
Failed to create content due to error: 04060050 Failed to execute script 'workspace://SpacesStore/953dc9e9-a847-4ce9-9667-83a9e393f8c4': 04060049 This action requires that either the template_string parameter or the template_node parameter be specified.

Not sure if I am doing this correctly any help appreciated.

Nick
7 REPLIES 7

swithun
Champ in-the-making
Champ in-the-making
I'm having similar trouble. I was having the same error, but I managed to get past it and on to other errors and now I'm stuck again.

My script is something like this:

var renditionDefName = "cm:adHocRenditionDef"; // can this really be anything?
var renderingEngineName = "xsltRenderingEngine";
var xsltString = "<?xml version='1.0' encoding='UTF-8'?>\
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\

</xsl:stylesheet>";

var renditionDef = renditionService.createRenditionDefinition(renditionDefName, renderingEngineName);
renditionDef.parameters["template_string"] = xsltString;
var result = renditionDef.execute(document);

I'm using the execute method, rather than the render method. And I'm using  the "template_string" property to get the XSL code in. Passing the path didn't work, and I couldn't figure out how to get a node reference. The wiki documentation always says:

NodeRef sourceNode = // obtained in the usual way e.g. from nodeService

which doesn't help if you don't know the usual way.

What I don't know is what kind of object, if any, is returned by execute. The above script runs without error, but also without any effect as far as I can see. My result variable is undefined, so I can't give it a name and save it. The XSLT will transform the XML document I'm running the script on (with xsltproc), so that isn't the problem.

swithun
Champ in-the-making
Champ in-the-making
After some digging around, I found that adding the destination-path-template parameter to the renditionDefiniton  let me save the rendered XML document, e.g.


var renditionDef = renditionService.createRenditionDefinition(renditionDefName, renderingEngineName);
renditionDef.parameters["destination-path-template"] = "/Company Home/test_folder/" + document.name + ".rendered.xml";
renditionDef.parameters["template_string"] = xsltString;
renditionDef.execute(document);

PARAM_DESTINATION_PATH_TEMPLATE: (String) this optional parameter indicates where the rendition will be created. The parameter may specify either the actual file path to the rendition or it may specify a Freemarker template which can be resolved to a file path. In either case the path is relative to the root node of the store in which the source node exists. If the parameter PARAM_DESTINATION_NODE has been set then this parameter will be ignored.

This is from http://wiki.alfresco.com/wiki/Base_rendering_engine.

swithun
Champ in-the-making
Champ in-the-making
Another way to get the XSLT document for use in the rendering is by using the template_node parameter:

renditionDef.parameters["template_node"] = search.findNode("workspace://SpacesStore/d903d0af-f12e-4be8-b017-084ee14a31d4");

The trick was finding the right method for getting a node from the node reference. 3.3_JavaScript_API#Search_API helps.

nick_vermeulen
Champ in-the-making
Champ in-the-making
Tried the .execute it returned this
   
  Please correct the errors below then click OK.
Failed to create content due to error: 04150032 Failed to execute script 'workspace://SpacesStore/4d5b0e42-175f-4018-88b8-f27931b24855': 04150031 TypeError: Cannot find function execute. (workspace://SpacesStore/4d5b0e42-175f-4018-88b8-f27931b24855#46)

Using the render function continues to return:
  Please correct the errors below then click OK.
Failed to create content due to error: 04150034 Failed to execute script 'workspace://SpacesStore/4d5b0e42-175f-4018-88b8-f27931b24855': 04150033 This action requires that either the template_string parameter or the template_node parameter be specified.

Code is as follows:

var renditionDefName = "cm:adHocRenditionDef"; // can this really be anything?
var renderingEngineName = "xsltRenderingEngine";

var renditionDef = renditionService.createRenditionDefinition(renditionDefName, renderingEngineName);

renditionDef.parameters["template-node"] = search.findNode("workspace://SpacesStore/449242b7-2ca2-4267-af0d-4d4484ad876a");
renditionDef.parameters["destination-path-template"] = "/Company Home/test_folder/" + document.name + ".rendered.xml";
// renditionDef.execute(document);
var rendition = renditionService.render(document, renditionDef);

Have tried both:
renditionDef.parameters["template-node"] = search.findNode("workspace://SpacesStore/449242b7-2ca2-4267-af0d-4d4484ad876a"); and
renditionDef.parameters["template_node"] = search.findNode("workspace://SpacesStore/449242b7-2ca2-4267-af0d-4d4484ad876a");

Not sure what I am doing wrong am running v3.3

Nick

swithun
Champ in-the-making
Champ in-the-making
It should be template_node, with an underscore, although destination-path-template uses hyphens.

I don't know why the method execute can't be found. How one would test the renditionDef variable for its type? That might tell you if the object is being created properly. Or is the TypeError caused by document not being instantiated? How is the script being called?

nick_vermeulen
Champ in-the-making
Champ in-the-making
Thanks. Not sure why the parameters use hyphens and underbars not exactly consistent!

I am calling the JavaScript from a rule attached to a space.  The rule is run when a document is added to the space. The script first of all makes a backup of the document and places it in a backup directory.  The code for that is as follows:

// find the xmloutput folder - create if not already exists
var xmlFolder = space.childByNamePath("iXBRL Files Backup");
if (xmlFolder == null && space.hasPermission("CreateChildren"))
{
   // create the folder for the first time
   xmlFolder = space.createFolder("iXBRL Files Backup");
}
if (xmlFolder != null && xmlFolder.hasPermission("CreateChildren"))
{
   // copy the doc into the backup folder to kept an audit
   var copy = document.copy(xmlFolder);
   if (copy != null)
   {
      // change the name so we know it's a backup
      copy.name = "Backup of " +  copy.name;
      copy.save();
   }
}

This part works and copies the document to the new folder. I think that means that document is set when I then make the call to the renderer.

How are you calling your renderer?  Have you had to install the xslt processor or change any variables to point to your processor.  I have made the assumption that the processor was included in the bundle I downloaded and that I don't need to config it at all.  Could be a big assumption.

Are you able to post all the code you have got to work and how you are calling it?  That would tell me if there is something wrong with my install of Alfresco.

swithun
Champ in-the-making
Champ in-the-making
This is a script that works for me:

var renditionDefName = "cm:adHocRenditionDef";
var renderingEngineName = "xsltRenderingEngine";
var xsltNode = "workspace://SpacesStore/6d01184c-50ce-4d2b-bc66-bb83e72735b0";
var destination = document.displayPath + "/" + document.name + "rendered.xml";

var renditionDef = renditionService.createRenditionDefinition(renditionDefName, renderingEngineName);

renditionDef.parameters["template_node"] = search.findNode(xsltNode);
renditionDef.parameters["destination-path-template"] = destination;

renditionDef.execute(document);

At the moment, I call it just on individual files, by doing Run Action and then Execute Script. I will want to use it as a rule later on. The template_node property is got by right clicking on Alfresco Node Reference for the XSLT document (stored in Rendering Actions Space) and copying the link address. Is there some other operation you can try which will test whether this node reference is found?

I do have a source version of Alfresco 3.3, checked out from SVN. But I don't think I've modified anything in this bit of Alfresco. If you have a source version, then the XSLTRenderingEngine class is found here:

Alfresco/HEAD/root/projects/repository/source/java/org/alfresco/repo/rendition/executer/XSLTRenderingEngine.java

If you just have a binary version, then you can see if you have XSLTRenderingEngine compiled in, with something like:

[archive@itspc-cs2 fits-0.3.1]$ find /opt/alfresco/tomcat/webapps/alfresco/ -name "*.jar" | xargs grep XSLTRenderingEngine
Binary file /opt/alfresco/tomcat/webapps/alfresco/WEB-INF/lib/alfresco-repository-3.3G.jar matches
Binary file /opt/alfresco/tomcat/webapps/alfresco/WEB-INF/lib/alfresco-web-client-3.3G.jar matches

I'm only just discovering all this stuff myself. I'm not sure what significant differences there could be in our setups.