EasyManua.ls Logo

Adobe 0046100128056 - InDesign - Mac - Duplicating XML Elements with XML Rules

Adobe 0046100128056 - InDesign - Mac
209 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CHAPTER 13: XML Rules XML Rules Examples 191
structure of an XML document are best done using an XSLT file to transform the document before or
during XML import into InDesign.
The following XML rule script shows how to use the move method to accomplish this. Note the use of the
__skipChildren function from the glue code to prevent the XML-rules processor from becoming invalid.
For the complete script, see MoveXMLElement.
main();
function main(){
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
//This rule set contains a single rule.
var myRuleSet = new Array (new MoveElement);
with(myDocument){
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
}
}
else{
alert("No open document");
}
//Adds a return character at the end of every XML element.
function MoveElement(){
this.name = "MoveElement";
//XPath will match on every part_number XML element in the XML structure.
this.xpath = "/devices/device/part_number";
// Define the apply function.
this.apply = function(myElement, myRuleProcessor){
//Moves the part_number XML element to the start of
//the device XML element (the parent).
__skipChildren(myRuleProcessor);
myElement.move(LocationOptions.before,
myElement.parent.xmlElements.item(0));
return true;// Succeeded
} //End of apply function
}
}
Duplicating XML elements with XML rules
As discussed in Chapter 12, “XML,” XML elements have a one-to-one relationship with their expression in a
layout. If you want the content of an XML element to appear more than once in a layout, you need to
duplicate the element. The following script shows how to duplicate elements using XML rules. For the
complete script, see DuplicateXMLElement. Again, this rule uses
__skipChildren to avoid invalid XML
object references.

Table of Contents

Related product manuals