Creating Page Items With Xml Rules - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
13: XML Rules
HAPTER
function ProcessPrice(){
this.name = "ProcessPrice";
this.xpath = "/devices/device/price";
this.apply = function(myElement, myRuleProcessor){
}
}
}

Creating page items with XML rules

The following script creates new page items, inserts the content of XML elements in the page items, adds
static text, and applies formatting. We include only the relevant XML-rule portions of the script here; for
more information, see the complete script (XMLRulesLayout).
The first rule creates a new text frame for each "device" XML element:
//Creates a new text frame on each page.
function ProcessDevice(){
this.name = "ProcessDevice";
this.xpath = "/devices/device";
this.apply = function(myElement, myRuleProcessor){
var myDocument = app.documents.item(0);
with(myElement){
}
return true;
}
}
The "ProcessType" rule moves the "type" XML element to a new frame on the page:
var myDocument = app.documents.item(0);
with(myElement){
insertTextAsContent("Price: $", XMLElementPosition.beforeElement);
//Add a return at the end of the XML element.
insertTextAsContent("\r", XMLElementPosition.afterElement);
applyParagraphStyle(myDocument.paragraphStyles.item("Price"));
}
return true;
insertTextAsContent("\r", XMLElementPosition.afterElement);
if(myDocument.pages.item(0).textFrames.length == 0){
myPage = myDocument.pages.item(0);
}
else{
myPage = myDocument.pages.add();
}
var myBounds = myGetBounds(myDocument, myPage);
var myTextFrame = placeIntoFrame(myPage, myBounds);
myTextFrame.textFramePreferences.firstBaselineOffset =
FirstBaseline.leadingOffset;
XML Rules Examples 202

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents