The following is a reference guide I have compiled over time for those of you who are looking at doing a little more with XML in InDesign (originally published Feb. 2011, last updated Feb 2018). If you have any extra information you’d like to see added to this guide, feel free to message me.
Mapping XML tags to InDesign styles
Mapping XML tags to styles, creates a link between content marked up with an XML tag and a paragraph, character style, table or cell style and will subsequently format the run-in XML data in the InDesign document based on the mapping references .
To map XML tags to various InDesign styles:
- Select Map Tags to Styles from the Tags panel menu or the Structure pane menu.
All Tags available in the Tags panel are listed. The Style menu provides a drop-down menu next to each Tag that contains a list of all Paragraph, Character, Table and Cell Styles to which Tags may be mapped.
- Click Map by Name in the Map Tags to Styles dialog box to automatically map matching Tag and Style names. All matching names are automatically linked up. For any Tags not mapped, you can choose an alternative mapping option from the drop down-menu.
- After you’ve linked all used tags to document styles, click OK.
Imported XML data is formatted now automatically formatted using the matched paragraph, character, table and cell styles.
When defining attributes that refer to a specific eXtensible Markup Language Namespace (XMLNS), the namespace must be declared as part of the XML. Where InDesign 4.0 and 5.0 namespaces are used, both namespaces may be entered in the Root element of the XML file or else inside the element referring to them.
Figure 1. InDesign Namespace reference for version 4 and 5.
An image reference in XML must provide a full path-name to the image location as a href attribute (this is similar to how the img tag works in HTML). When you apply an Object Style to the graphic frame that sets the frame options, you can control the positioning and scaling of the image as it is being placed in a tagged graphic frame during XML import.
|Image element sample|
Figure 2. Example of Image element with reference to image location
|Image reference examples|
|Images stored in same folder as xml file||
|images stored in a sub folder inside the same folder as xml file||
|Images stored anywhere and referenced by accessing the full path name. This is referred to as an absolute path name||In the Documents folder on your PC:
|In the Documents folder on your Mac:
|Where username is to be replaced with your username (in my case that would be “carijansen”) and RestOfPath points to sub and sub-sub-folders inside the Documents folder|
|Images stored on another volume (server)||from a Macintosh OS: F
|Where VolumeName reflects the volume.
from Windows: F
Where ServerName reflects the name of the Server you’re connected to.
Figure 3. Image path samples.
Tables in InDesign CS3 and higher can be formatted using Table and Cell Styles.
These styles may be applied as part of the XML import by including appropriate style attributes to the XML table. The following attributes can be applied:
||defines that the element is a table|
||total number of rows the table contains|
||total number of columns the table contains|
||(ID5 specific), Table Style that formats the table|
||defines cells as being part of a header row|
||defines cells as being part of a footer row|
||(ID5 specific), Cell Style that formats table cells|
||number of rows across which the cell spans<|
||number of columns across which the cell spans|
||column width of cell, measured in points|
Figure 4. Table attributes.
Figure 5. Table XML sample.
Note that a table cannot be placed into InDesign without its parent Story element. The aid and aid5 prefixes used as part of the attribute names that define specific cell formatting are indicative of these names being part of the InDesign 4.0 and 5.0 XML namespaces.
Paragraph and character styles
Formatting with paragraph or character styles can also occur during XML import and works similar to using the table attributes. Use the following attributes for paragraph or character level formatting:
||Paragraph Style formatting|
||Character Style formatting|
Figure 6. Paragraph and character style attributes.
Figure 7. Paragraph and character style XML sample.
List of special characters (I’ll add to this over time, feel free to message me if you have additions):
Figure 8. Special characters.
Is there any xml structure for creating and applying group paragraph style?
I’m working on producing a suite of InDesign documents, which will be populated using XML data, taken from our website.
Some of the fields have inline styles, which appears as part of the text, when imported in to InDesign. (see below for example)
<![CDATA[ Students often elect to undertake field trips either individually or as a group as part of their broad range of study. Bristol Zoo and a local zoo farm are favorite locations for the study of animals for Action Analysis studies.You’ll be given the opportunity to work with the British Film Institute (BFI) Animation Boot Camp, which provides workshop instruction for young people from around the UK. ]]>
Is there any way to get InDesign to recognise this styling and either implement it or remove it?
I have to show two tables side by side , so i was thinking to create a parent table of single row with two cell. and in those two cell want to put two other tables.
however i am not able to nest tables. ie. when i am importing this xml , it is failing.
is there any solution for this problem
What you could try and do is have an external paragraph style for your tables, that has span columns set to split 2, but it will be a bit of a hit and mis to get them to position perfectly side by side…
I’m creating a catalog. I have manage how to flow an XML, styling, and so on, thank to your tutorials.ButiIn this catalog, I have to create two patterns : 1) 4 articles with details/page 2) many articles with less details (same collection)/page. I don’t manage to tell to ID that there two different structures in my XML. How can I manage to create two different repeating patterns ?
You’d need to run a script on import I believe, and insert an attribute for each collection of content that flags which of the run in pattern needs to be used. The script will then ensure that the right master pages are used for the XML run in.
I have a xml where same tag is used for head 1, head 2. I can’t change the tag, is there any way to add attribute and map that attribute with indesign style.
You’ll need to use an XSLT on import to change the tag based on the position in the text it appears in.
@locavore afaik there are no public updates for this. Adobe has however released more documentation on IDML. See: http://www.adobe.com/devnet/indesign/documentation.html
Where can we find out if there are any changes to XML namespace in more recent versions of InDesign (CC)? There is no online reference that I can find that says specifically if it is the same. I’d like to verify that the aid: should be changed or not for tables in InDesign CC
You can use a workaround:
if you need to access styleNameA in a style group, transform the <p aid:pstyle=”styleNameA”> to <styleNameA>, this way all you need to do is add a new style-mapping from </styleNameA><styleNameA> to “styleNameA (StyleGroupName)” .</styleNameA></p>
Hi Cari, i didn’t understand that:
For example in
I want to get the “EK” paragraph style in a style group called “text”
Table header 1
I want to get the “h2” in a style group called “headers”.
How do you do that?
@studiovanpelt What is it you are trying to achieve? if you have a pstyle assigned as part of your xml import, it doesn’t map to a style inside a style group. If you are referring to a style group as part of xml-import you’ll likely need to use an xslt to get the import working, or xml-import script of sorts. Cari
id:pstyle with style in style group?
When i imported xml file into indesign version 6 “” as per your guidance aid:pstyle=”para” file not mapped as per style please advice.
did you add the ns info to the start of the XML file? Is the paragraph style ‘para’ added in the paragraph styles panel? if it is in a style group remove it from the style group and add it at top level.
Hi Cari, Where shall a person find beginning instruction to use XML with InDesign? Thank you.
Thanks for the valuable information about “aid” concept.
How do we handle “Style Group” paragraph style.
Using “aid:pstyle” it won’t work for Style Grouped paragraph style.
Is there is any attribute which can handle the style grouped style.
@Johnny you’re most welcome. Glad it was helpful 🙂 Cari
No, it was actually my typo, not yours, that was the issue. By the way, this is one of the most helpful and informative blog posts EVER. Thank you SO MUCH!
Not a problem Johnny. I’ve just reviewed the XML Notes in my blog post and fixed the ‘smart-quotes’ which I think might be the typo you were referring to? When I have some spare time I’ll add some additional notes to this blog-posts. Have added it to my list as a post that needs updating 🙂 Cari
Please disregard my last message. I figured it out. A typo in the namespace declaration that you illustrated in Figure 4.
Thank you for this very helpful tutorial. I’m importing a table into my InDesign 5.5 file using XML. The table data shows up fine, but it’s not formatted, even though I have a basic table style and I’ve linked it to the table tag name. What’s strange is that when I select the data, the table styles are all greyed out, meaning it won’t let me apply a table style to the data. Have you ever run into this or do you know why it might be doing this? Thanks so much.
Anwer, I mean update.:). BTW, Does Image is always referred using href or it can come without href tag? We are trying read indt XML programitically and wanted to have some reference base which will be always there to indicate image in XML.
@SME I was afraid that would be the answer 🙁 🙁
Thanks for answer. It doesn’t work. We tried but no success. 🙁
@SME Hmmm… interesting question. I’ve never tried that, and my gut feel says ‘no’, as I’m not sure how InDesign could pull in the graphic and retain a link to it. As far as I’m aware, InDesign doesn’t support placing web graphics. But if you do get that working let us know for sure 🙂
Can I use internet location for image tag? If Yes, how it would look like in XML?
@locavore interesting… must test that… I generally ensure when data is extracted from a database into XML-for-InDesign format, the row count is set.
Seems to me I had success leaving the aid:trows value empty (the rows would be calculated from the cells) — and if I set it to an arbitrary number, the table would truncate when it got to the value that matched cells count divided by that number. This was for a table that ran for many pages with repeating heads, developed quite some time ago and probably needs to be retested to verify aid:trows=”” is OK to use.
To give you a real life example: I developed an XML repetitive run-in template that generated a list of public schools some time ago and and each had their school crest included as part of the XML import. The crest needed to be fully visible and centered in a placeholder graphic frame.
I guess in a way it depends on the kind of document template you are working on as to which works best.
You mentioned, “When you apply an Object Style to the graphic frame that sets the frame options, you can control the positioning and scaling of the image as it is being placed in a tagged graphic frame during XML import.”
You can use something like Oxygen XML Editor. Another one would be Stylus Studio (Windows only). As far as I’m aware both allow to build XSLT, apply to XML and see/test result.
Thanks for the suggestions. I’ll look into the XSLT row count – sounds like something to get my teeth into! In the meantime, I’ve changed the XSLT to create a table with two rows for each record and it works a treat.
I’ve been attempting to remove empty elements using XSLT, but can’t seem to get it to work. I can’t work out whether it’s down to part of the XSLT (I’ve tried several examples from the net) or the way Indesign interprets it. Do you know of any software that will allow me to work on the Indesign XSLT ‘live’ (similar to the way Dreamweaver will allow you to work on live code)?
Where I’ve worked with table data, we’ve calculated the amount of ‘rows’ (records) exported, so that the row number can be defined properly. You could possibly do this with XSLT as well (you’d need to check with an XSLT expert). The same applies for the empty elements, you can remove these during import (XSLT) or prior to import using something like a ‘GREP’ Find/Replace even.
Thank you for this information, I’ve learned a lot about Indesign, XML, and XSLT in the last couple of weeks. I’m using some of these tips in a document I’m creating (Club Diary). Exported XML from Access, importing and applying an XSLT with aid: tags present to define character styles in a table.
I do have a couple of questions:
1. Do you have to specify a number of rows (in aid:trows=”xx”)? As the data coming from the database could contain any number of records (and therefore rows) it would be preferable to not have to specify a number in this attribute.
2. When importing XML and a blank field is encountered, is it possible to not display the field placeholder and remove the blank space between lines?
Yes, my question is about adding multiple unique attributes to a tagged element (span) via the Structure pane. Experimentation revealed that a space between values works, though I’m not sure about why that works. Any insight into how the attributes are managed by InDesign would be appreciated.
@Dan: did you try entering “class” as the attribute name and then two words separated by a space for the attribute values. i.e. “italic text-indent” (without the quotes)? This works for me in IDD CS5.5 using the Attributes dialog.
If you are using a DTD then both the attribute name and the attribute values must be valid. It looks like you are imitating HTML syntax, in which case the class attribute and free-text values for it are OK. For example:
<p class=”h1 title article”>A title</p>
<p class=”body no-indent”>A paragraph with an inline <emphasis class=”italic”>emphasis</emphasis> and <keyword class=”bold italic keyword”>keyword</keyword>.</p>
You could remap this with XSLT during export to achieve HTML like this:
<h1 class=”title article”>A title</h1>
<p class=”body no-indent”>A paragraph with an inline <em class="italic">emphasis</em> and <b class="bold italic keyword">keyword</b>.</p>
It is pretty easy to map from a paragraph or inline XML element to similar HTML elements. If you need to make complex groups of content into nested divs, you will probably need more complex XSLT for your grouping. Note that if you want to build a complete HTML file from InDesign content, you have to define the html, title, and body elements in the XSLT and then you need to determine how to handle each separate text flow that you have tagged in the InDesign file, whether it should be in its own div in HTML or not.
In my InDesign document I have a span element that requires an attribute named class with two values: “italic” and “text-indent”. But InDesign won’t allow me to have two attributes identically named, and both require the same name (class). Is it possible to enter multiple values in the Edit Attribute dialog box value field for a single class attribute? If so, what is the separator?
I’m not sure what tag in the structure panel you are trying to add an attribute to, but you can add multiple attributes to a tag when setting up structure for XML in InDesign. What you can’t do is add two attributes with the same name. Are you applying the attributes via the Structure pane?
I am looking for a way to format column width other than using points. I am looking for a way to have the columns withs in tables to be relative like in SGML 1* or 2* or even 1.7* and I would want to mix this with fixed widths e.g.:
first col be always 100 points; second col be relative 1; third col be relative 2; and last be 80 points.
Can indesign compute this if the width of the table is known?
You’d need to run an XSLT on import that calculates this for you. E.g. if you know in advance what the overall width of the table would be, and you’ve got ‘proportional’ settings e.g. Column 1 20%, Column 2 40% etc. you can get your XSLT to convert this to points during InDesign XML import.
Alternatively, you could run a script that processes columns proportionately to the width of the parent text frame they appear in.
Pleasure @SSHunho I think you’ll most likely need to customise with scripting for object style level support. – CJ
Many thanks for the articles. I’ve learned a lot about InDesign XML attributes and InDesign Namespaces. This is really useful.
Just a quick question. Does InDesign XML support Object Styles as it is with Paragraph and Character style attributes? Is there anyway I could include object style in the XML?
Very useful! Thank-you.
The tag got removed from the comment. I wanted to say that the tag does not have to be named “Image” for InDesign to expect linked images.
Worth pointing out that images don’t have to be linked using a tag named “”. InDesign will assume the href attribute of any tag is for an image.
I have an XML file with table and I have converted this table to CALS table and added indesign style through XSLT. Unfortunately, the styles are not applied when the XML is improrted to Indesign. Can any one suggest a solution pleae?
Thanks lot for this article!
I have a related problem that made me google for hours and still not found any answer.
I have Indesign tagged tables that I’d like to export to xml, but I need them without the “aid:” elements. When I untag all the text in a table, it exports fine, but when I tag any paragraph or other element inside that table, the “aid:” arise, and the final xml should’t have them. Is this possible?
Thanks in advance
@Loic 🙂 great idea 🙂
Thx for your answer. It’s really encouraging 🙂
A script ? You should keep in touch with marc who should really enjoy such a project 😉
Yes XML means you don’t need to work with everything inline to get EPUB content in the correct order.
It is by no means perfect, but it does mean that hypothetically speaking you wouldn’t need to redesign your publications for EPUB output if they already exist in for print-layout purposes.
But I must be honest and say that practically speaking it is often quicker to build an inline document.
A way around that would be for someone to develop a script that could assist in building the XML structure. A script for instance that recognises groups and inserts those as ‘nested’ tags 🙂
The script I think would also need to review the default ‘tagging’ order when we use ‘AutoTag”. 🙂
Yes, I heard about XML/epub relationship but never really played with it. Waiting for your next post so it can answer one of my questions ie does using xml tagging avoid setting an unique flow (anchored objects etc…) or is it just for ordering contents ?
@Loic, Merci beaucoup pour les mots gentils!
XML can also be used for EPUB creation. a) you can control which content is going to be included in the EPUB through the Structure inclusion and b) you can control the order in which it will appear in the EPUB.
I hope to do a write-up about that at some point, have so many other things to do at the moment 🙂 Just need more hours in the day 🙂
Yes, this one rocks !!! Set styles on XML structure is very promising 🙂