How to map xml attribute to style?

New Here ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

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?

TOPICS
How to

Views

106

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 04, 2022 Jul 04, 2022

Copy link to clipboard

Copied

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

Mike Witherell

Likes

Translate

Translate

Report

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
New Here ,
Jul 07, 2022 Jul 07, 2022

Copy link to clipboard

Copied

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  

Likes

Translate

Translate

Report

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
Guru ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

LATEST

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

2022-07-08_10-48-24.png

 

 

 

Likes

Translate

Translate

Report

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