Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Mapping XML Tags to Styles Indesign Scripting

New Here ,
Mar 25, 2019 Mar 25, 2019

Hi guys, so i've uploaded a xml file to my current document. I'm working through this api and i'm currently trying to style the xml tags that I have imported using a template. Please take a look at my code and tell me what I am missing.

Setup.js:

var myDocument = app.open(File(app.activeScript.parent.fsName + '/firstTemplate.indt'));

var curFile = app.activeScript.parent.fsName + '/library.xml';

myDocument.importXML(File(curFile));

// need to apply styling to tags

myDocument.mapXMLTagsToStyles();

var root = myDocument.xmlElements[0]; // root

var element = root.xmlElements[0];

root.placeXML(myDocument.textFrames[0]);

myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

var price = root.evaluateXPathExpression('//pricing');

My Indt file has paragraph stylings that are to be applied to any document I run the script on just as long as the same xml tags match up to the styling.

Thank you!

TOPICS
Scripting
2.5K
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

correct answers 1 Correct answer

People's Champ , Mar 26, 2019 Mar 26, 2019

mapXMLTagsToStyles doesn't work differently in scripting than in UI. You need to let InDesign know which styles have to be bound to tags through xmlImportMaps which can be translated by the map tags to styles in the tags panel :

var myImportMap = doc.xmlImportMaps.add(myTag,myStyle);

doc.mapXMLTagsToStyles();

Translate
People's Champ ,
Mar 26, 2019 Mar 26, 2019

mapXMLTagsToStyles doesn't work differently in scripting than in UI. You need to let InDesign know which styles have to be bound to tags through xmlImportMaps which can be translated by the map tags to styles in the tags panel :

var myImportMap = doc.xmlImportMaps.add(myTag,myStyle);

doc.mapXMLTagsToStyles();

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
Participant ,
May 17, 2023 May 17, 2023

@Loic.Aigon Is there a way to force Indesign to re-apply an existing map, or import a map from another file (i.e. a template file)?

 

I am moving XML elements between files, but the existing map is not being applied to the new elements properly.

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
People's Champ ,
May 17, 2023 May 17, 2023

Given that the UI doesn't allow to import such rules, the DOM doesn't expose such functionnality.

That said, recall 

var myImportMap = doc.xmlImportMaps.add(myTag,myStyle);

doc.mapXMLTagsToStyles();

and that should do it (once again in the UI, if you reset styles maps, contents styling get updated).

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
Participant ,
May 17, 2023 May 17, 2023

@Loic.Aigon The trouble I was having was that adding just a single style seems to remove all of the other mapped styles. Do I need to re-map ALL of my mapped styles within the script?

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
Participant ,
May 17, 2023 May 17, 2023
LATEST

@Loic.Aigon  I take it back, re-mapping the one style seems to have worked.

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