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

How to map xml attribute to style?

New Here ,
Jun 30, 2022 Jun 30, 2022

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
281
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 ,
Jul 04, 2022 Jul 04, 2022

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

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

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

 

 

 

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