Skip to main content
Participant
July 1, 2022
Question

How to map xml attribute to style?

  • July 1, 2022
  • 3 replies
  • 275 views

Hi,

Let say i have this simple xml file:

<root>
<p align="right">
</root>

How can i map the align="right" with 'align right' in indesign? Is there any example script that i can refer to?

This topic has been closed for replies.

3 replies

Kasyan Servetsky
Legend
July 8, 2022

I assume that you want to achieve this by script. Here's an example and a test file attached:

main();

function main() {
	var xmlEl, xmlContent, xmlAttr, alignment,
	doc = app.activeDocument,
	root = doc.xmlElements[0],
	xPath = "//p[@align]",
	xmlElements = root.evaluateXPathExpression(xPath);
	
	for (var i = 0; i < xmlElements.length; i++) {
			xmlEl = xmlElements[i];
			xmlContent = xmlEl.xmlContent;
			xmlAttr = xmlEl.xmlAttributes.itemByName("align");
			alignment = xmlAttr.value.toUpperCase();
			xmlContent.justification = eval("Justification." + alignment + "_ALIGN");
	}
}

 

 

 

Participant
July 7, 2022

Hi @Mana5D15 ,

Example as follows 

<root>
<p aid:pstyle="alignRight">Example text that will be aligned right</p>
<root>

You need to change you "align" attribute name to "aid:pstyle" as that is an attribute name that is fixed for InDesign to pick up. Once you import that xml into your Indesign document, it should be styled with the "alignRight" paragraph style.  I use this xml attribute assignment method for Indesign tables, especially cascading ones.

Some documentation on this is here Adobe InDesign CS3 and XML: A Technical Reference    

Any questions (no matter how silly! I know documentation isn't great for Adobe) fire away, happy to help.

Jake  

Mike Witherell
Community Expert
Community Expert
July 4, 2022

Why not define this in the Paragraph Style (at the bottom of that dialog box is a pane for Export Tagging)?

Mike Witherell