Indesign scripting create deeper structures by adding tags
I first set out to do this with XSLT, then with PHP. Now i'll have to have a go at it with Indesign scripting (javascript probably)
My problem is that i have an indesign file without structure (nothing is tagged, but everything has a paragraph style)
Wat i have to do is 1) ad tags to paragraphs based on their styles 2) deepen the structure by adding parent-elements to the tags
An example:
This text:
Titel 1 (style = title1)
Titel 2 (style = title2)
some text (style = text1)
listitem 1 (style = listitem)
listite开发者_高级运维m 2 (style = listitem)
Has to become (on export to XML)
<GR.SEQ level="1">
<TITLE>
<TI>
<HT>
Titel 1
</HT>
</TI>
</TITLE>
<GR.SEQ level="2">
<TITLE>
<TI>
<HT>
Titel 2
</HT>
</TI>
</TITLE>
<P>
some text
</P>
<LIST>
<ITEM>
<ITEM.CONT>
listitem 1
</ITEM.CONT>
</ITEM>
<ITEM>
<ITEM.CONT>
listitem 2
</ITEM.CONT>
</ITEM>
</LIST>
</GR>
</GR>
Any help is appreciated! a code-example that does this would be marvelous but a push in the right direction is also very welcome.
I would be very pleased already when i could change this:
Titel 1
to this
<TITLE>
<TI>
<HT>
Titel 1
</HT>
</TI>
</TITLE>
First you have to define an XMLExportMap-Object for each Paragraph/Tag like this:
<yourDoc>.xmlExportMaps.add(<yourParagraphStyle>, <yourParagraphStyle>.name);
(Rather consider that there is no whitespace in your Style-Names)
When you defined all, then you call following method:
<yourDoc>.mapStylesToXMLTags();
As a result there should be a flat XML-structure in the Root-element then
Then: There are some abilities to use Xpath with InDesign and Javascript, but in my opinion hard to use and very less implemented.
So I appreciate to export the flat XML-Structure and apply an XSL-Stylesheet to get a deepened structure.
Hope that helps
精彩评论