C
13: XML Rules
HAPTER
Applying multiple matching rules
When the
XML rules to the matched XML element. When the
processor can apply other rules to the XML element. The following script shows an example of an XML-rule
function that returns false. This script contains two rules that will match every XML element in the
apply
document. The only difference between them is that the first rule applies a color and returns false, while
the second rule applies a different color to every other XML element (based on the state of a variable,
myCounter
main();
function main(){
myCounter = 0;
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
//Define two colors.
var myColorA = myDocument.colors.add({model:ColorModel.process,
colorValue:[0, 100, 80, 0], name:"ColorA"});
var myColorB = myDocument.colors.add({model:ColorModel.process,
colorValue:[100, 0, 80, 0], name:"ColorB"})
var myRuleSet = new Array (new ReturnFalse,
with(myDocument){
}
}
else{
alert("No open document");
}
//Adds a color to the text of every element in the structure.
function ReturnFalse(){
this.name = "ReturnFalse";
//XPath will match on every XML element in the XML structure.
this.xpath = "//*";
this.apply = function(myElement, myRuleProcessor){
}
}
//Adds a color to the text of every other element in the structure.
function ReturnTrue(){
this.name = "ReturnTrue";
function of an XML rule returns true, the XML-rules processor does not apply any further
apply
). For the complete script, see ReturningFalse.
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
with(myElement){
myElement.texts.item(0).fillColor =
app.documents.item(0).colors.item("ColorA");
}
// Leaves the XML element available to further processing.
return false;
apply
new ReturnTrue);
function returns false, however, the XML-rules
XML Rules Examples 194