Adobe 0046100128056 - InDesign - Mac Manual page 189

Javascript
Table of Contents

Advertisement

C
13: XML Rules
HAPTER
//Adds static text around the "minimum" and "maximum"
//XML elements of the "supply_voltage" XML element.
function ProcessSupplyVoltage(){
this.name = "ProcessSupplyVoltage";
this.xpath = "/devices/device/supply_voltage";
// Define the apply function.
this.apply = function(myElement, myRuleProcessor){
} //End of apply function
}
function ProcessPackageType(){
this.name = "ProcessPackageType";
this.xpath = "/devices/device/package/type";
// Define the apply function.
this.apply = function(myElement, myRuleProcessor){
} //End of apply function
}
//Add the text "Package:" before the list of packages.
function ProcessPackageOne(){
this.name = "ProcessPackageOne";
this.xpath = "/devices/device/package[1]";
this.apply = function(myElement, myRuleProcessor){
} //End of apply function
}
//Add commas between the package types.
function ProcessPackages(){
this.name = "ProcessPackages";
this.xpath = "/devices/device/package";
this.apply = function(myElement, myRuleProcessor){
//Note the positions at which we insert the static text. If we use
//XMLElementPosition.elementEnd, the static text will appear
//inside the XML element. If we use XMLElementPosition.afterElement,
//the static text appears outside the XML elment (as a text element of
//the parent element).
with(myElement){
//Add static text to the beginning of the voltage range.
insertTextAsContent("Supply Voltage: From ",
XMLElementPosition.elementStart);
with(myElement.xmlElements.item(0)){
insertTextAsContent(" to ", XMLElementPosition.afterElement);
}
with(myElement.xmlElements.item(-1)){
//Add static text to the beginning of the voltage range.
insertTextAsContent(" volts", XMLElementPosition.afterElement);
}
//Add a return at the end of the XML element.
insertTextAsContent("\r", XMLElementPosition.afterElement);
}
return true;// Succeeded
with(myElement){
insertTextAsContent("-", XMLElementPosition.afterElement);
}
return true;
with(myElement){
insertTextAsContent("Package: ", XMLElementPosition.elementStart);
}
return false; //Return false to let other XML rules process the element.
with(myElement){
if(myElement.parent.xmlElements.nextItem(myElement).markupTag.name ==
"package"){
insertTextAsContent(", ", XMLElementPosition.elementEnd);
XML Rules Examples 189

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents