Copy link to clipboard
Copied
When I use import xml manually into indesign, it works - but when I import it using the script below, it does not apply the transformation.
Any ideas?
with(app.activeDocument.xmlImportPreferences) {
allowTransform = true;
transformFilename = XMLTransformFile.STYLESHEET_IN_XML;
createLinkToXML = false;
ignoreWhitespace =true;
ignoreUnmatchedIncoming = false;
importCALSTables = true;
importToSelected = false;
allowTransform = false;
importTextIntoTables = true;
repeatTextElements = false;
removeUnmatchedExisting = false;
importStyle = XMLImportStyles.MERGE_IMPORT;
}
Copy link to clipboard
Copied
Um. Is this all? It sets the preferences, but doesn't do anything else.
You need an additional line with "importXML" (with all of its parameters, etc.) to "do" the import ...
Copy link to clipboard
Copied
The rest of the import is as follows: (with some checking code for my own purposes)
try {
contentLayer = app.activeDocument.layers.itemByName("ImportedContent").remove();
}catch(e) { }
contentLayer = app.activeDocument.layers.add({name:"ImportedContent"});
newFrame = app.activeDocument.textFrames.add();
newFrame.geometricBounds = [0.736,0,10.3783819742489,7.75];
xmlFile2 = File(xmlFile.path+ "/" + xmlFile.name.split(".xml")[0] + "-ST.xml");
greenLight = 0;
if (xmlFile.exists) { passedFile = xmlFile;greenLight++; }
else if (xmlFile2.exists) { passedFile = xmlFile2;greenLight++; }
if (greenLight !=0) {
try {
app.activeDocument.importXML(passedFile);
newFrame.placeXML(app.activeDocument.xmlElements[0]);
app.activeDocument.mapXMLTagsToStyles();
The reason I didn't post this before is that the xml imports without any issues, it just does not apply the stylesheet, so I assumed something is wrong in my import preferences that I'm not seeing.
If I manually import it, it works.
Copy link to clipboard
Copied
Okay -- just wanted to make sure ![]()
Never used this myself ... Only other thing I can think of is: does it work if you do supply the XSLT filename?
Copy link to clipboard
Copied
Same result, its as if InDesign is completely ignoring the transform command.
Edit: Tried giving it both a File and String reference to the XSL file and the behavior is the same...what am I missing?
Message was edited by: Pat R O'Neill
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Stumbled on that one too, sadly no. I'm using a pc with WinXP.
Copy link to clipboard
Copied
Still no luck despite anything I try. I guess the bug on applescript is in the javascript implementation as well.
Copy link to clipboard
Copied
i just took the time to test a simple configuration. neither stylesheet in xml nor a separate stylesheet file works on cs3 via scripting (running a windows her, on mac it's it's not working too). in cs4 everything works fine, cs5 ist not around.
by the way, indesings xsl processor in cs3,4,5 is rather crappy. i do any reasonable transformation outside of indesign with saxon 9. you can process a batch file or command line easily via scripting.
regards,
gregor
Copy link to clipboard
Copied
arrgh, this was not was i wanted to test: it works with cs3 if you omit the with {} statement.
if you set the xmlImportPreferences direct it does work here.
app.activeDocument.xmlImportPreferences.allowTransform = true;
app.activeDocument.xmlImportPreferences.transformFilename = XMLTransformFile.STYLESHEET_IN_XML;
so this is not working:
var _file = File.openDialog ("Choose XML File");
with(app.activeDocument.xmlImportPreferences) {
allowTransform = true;
transformFilename = XMLTransformFile.STYLESHEET_IN_XML;
//transformFilename = File.openDialog ("Choose XSL File");
}
app.activeDocument.importXML(_file);
but this works fine:
var _file = File.openDialog ("Choose XML File");
app.activeDocument.xmlImportPreferences.allowTransform = true;
app.activeDocument.xmlImportPreferences.transformFilename = XMLTransformFile.STYLESHEET_IN_XML;
//transformFilename = File.openDialog ("Choose XSL File");
app.activeDocument.importXML(_file);
Copy link to clipboard
Copied
Thank you for the help, but this was a painfully obvious case of PEBKAC on my part.
Go back through the code quickly if you want a good laugh and tell me why it didn't work. ![]()
Copy link to clipboard
Copied
Just a guess: Was there no XSL specified in the XML?
Copy link to clipboard
Copied
Even simpler than that:
allowTransform = true;
transformFilename = XMLTransformFile.STYLESHEET_IN_XML;
createLinkToXML = false;
ignoreWhitespace =true;
ignoreUnmatchedIncoming = false;
importCALSTables = true;
importToSelected = false;
// D'OH!
allowTransform = false;
// D'OH!
importTextIntoTables = true;
repeatTextElements = false;
removeUnmatchedExisting = false;
importStyle = XMLImportStyles.MERGE_IMPORT;
Copy link to clipboard
Copied
You are right ... I did not see it last week and didn't just now -- even while making sure I read every single line.
You may give yourself some points for finding it out by yourself ![]()
Copy link to clipboard
Copied
After trying Grefel's post and having it still not work, I tried going through line by line and nulling or falsing everything to "reset" the preferences.
Thats when I noticed it.
Partial points were handed out. Just glad to get this script back on track to meet deadline.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now