Copy link to clipboard
Copied
xsl script have been developped, so I would like to call xsl scripts developed inside ExtendScript in order the users don't need to save .FM as .xml, then, run xslt script to transfter the other .xml format. Is it possible?
Thanks.
Here is a general purpose function that you can use to invoke an XSLT transform:
function runTransformation (transform) {
/* transform is a JavaScript object:
.xml = absolute path to the file to transform
.xsl = absolute path to the XSL stylesheet
.pro = XSLT processor (SAXON)
.out = absolute path to the transformed file.
.console = true to show the Console,
false to suppress the Console
.params = an array of objects containing
...
Copy link to clipboard
Copied
I suspect that Jang Graat will respond, but here is a link to one of his blog posts to get you started:
https://blog.adobe.com/en/publish/2017/11/21/xslt-support-in-framemaker-2017
If I have time later, I will post some example code. I use this feature extensively in my ExtendScript scripts to run XSLT stylesheets. FrameMaker has the Saxon Enterprise Edition built in and you can do a lot with it from your scripts.
Copy link to clipboard
Copied
Thanks for your quick reply.
I will be really appreciate if you have time to post some example code in order for me to understand better and hand on it quickly. Thanks again.
Copy link to clipboard
Copied
By the way, I have read that artical before and also followed steps to call CallClient() but nothting is happened .. so, I would like to have same example code to study how to make it work. One more question, should we change the setting of FrameMaker in the meanwhile? Thanks a lot.
Copy link to clipboard
Copied
Here is a general purpose function that you can use to invoke an XSLT transform:
function runTransformation (transform) {
/* transform is a JavaScript object:
.xml = absolute path to the file to transform
.xsl = absolute path to the XSL stylesheet
.pro = XSLT processor (SAXON)
.out = absolute path to the transformed file.
.console = true to show the Console,
false to suppress the Console
.params = an array of objects containing
name/value pairs (optional)
*/
var cmd, count, i, result;
// Create the command string.
cmd = 'XSLTRunTrScenario ' +
'-file \"' + transform.xml + '\" ' +
'-xslfilepath \"' + transform.xsl + '\" ' +
'-processor \"' + transform.pro + '\" ' +
'-outputfilepath \"' + transform.out + '\"';
// See if Console messages should be displayed.
if (transform.console === false) {
cmd += " -dontusefmconsole";
}
// Add any parameters to the command line.
count = transform.params.length;
for (i = 0; i < count; i += 1) {
cmd += ' -sparam ' + transform.params[i].name + ' "' +
transform.params[i].value + '"';
}
// Invoke the transform.
result = CallClient ("FmXSLT", cmd);
}
Copy link to clipboard
Copied
Thanks a lot for your general purpose code! now I got the "result = -1" which is better than before, returns something;-).
The command used is shown below (without params (Optional)),
<XSLTRunTrScenario
-file "C:\temp\chapters_structured.xml"
-xslfilepath "C:\temp\test.xsl"
-processor "SAXON"
-outputfilepath "C:\temp\chapters_structured_after.xml">
Is the command wrong? by the way, what should be set for "sparam"? Is it possible to explain a little bit about this with the example? Thanks.
Copy link to clipboard
Copied
You want to put all of your XSLTRunTrScenario into a string variable (without the angled brackets in your example) and then pass it to this call:
// Invoke the transform.
result = CallClient ("FmXSLT", cmd);
where cmd is your string variable.
Copy link to clipboard
Copied
"cmd" posted before is copied from data structure and I added < > that to show the command line, excuse me for the confustion.
Here is my whole code for this operation:
var transform = new Object();
transform.xml = "C:\temp\chapters_structured.xml";
transform.xsl = "C:\temp\test.xsl";
transform.pro = "SAXON"
transform.out = "C:\temp\chapters_structured_after.xml"
transform.console = true;
cmd = 'XSLTRunTrScenario ' +
'-file \"' + transform.xml + '\" ' +
'-xslfilepath \"' + transform.xsl + '\" ' +
'-processor \"' + transform.pro + '\" ' +
'-outputfilepath \"' + transform.out + '\"';
result = CallClient ("FmXSLT", cmd);
alert("CallClient result:" + result);
Copy link to clipboard
Copied
Everything looks correct. A couple of things to check: Are you getting any messages to the Console window? Also, I would put this in my code:
Console (cmd);
so you can check your command line string for correctness; for example, matching quotes, etc. Add this to your code and post the Console message here. Thanks.
Copy link to clipboard
Copied
It works now 🙂 The root cause is that I made a mistake which the output file wasn't created before calling CallClient() ... thanks a lot again for your advices and quick responses 🙂
Copy link to clipboard
Copied
sparam is an optional set of name/value pairs for passing parameters to your stylesheet.
Copy link to clipboard
Copied
Got it.
By the way, result still returns "-1" even when "Transformation Successful" is printed in Console window. Any idea? Thanks a lot.
Copy link to clipboard
Copied
FrameMaker API clients can have an integer return value and 0 is typically returned for success. Apparently, not all API clients are programmed this way, so I generally ignore the return value. As far as I know, there is no public documentation for the FmXSLT client, although I have requested documentation from Adobe. Here is a screenshot from the FDK Reference that may be helpful: