Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

XML Won't Transform in Batch [JS, CS3]

Explorer ,
Jun 15, 2010 Jun 15, 2010

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;
    }

TOPICS
Scripting
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2010 Jun 15, 2010

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 ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2010 Jun 15, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2010 Jun 15, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2010 Jun 15, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2010 Jun 15, 2010

Do you use a Mac? There is a bug with XML-Transform


http://forums.adobe.com/message/1110847#1110847

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2010 Jun 15, 2010

Stumbled on that one too, sadly no. I'm using a pc with WinXP.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 17, 2010 Jun 17, 2010

Still no luck despite anything I try. I guess the bug on applescript is in the javascript implementation as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2010 Jun 20, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2010 Jun 20, 2010

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2010 Jun 21, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2010 Jun 21, 2010

Just a guess: Was there no XSL specified in the XML?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2010 Jun 21, 2010

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2010 Jun 21, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2010 Jun 21, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines