PTC ALD in Arbortext Styler > Components of Documents and Templates > Conditional Text Formatting > Conditional Formatting > Content and Context Tests with XPath
Content and Context Tests with XPath
Using XPath to Test Content
XPath can be used to test for items which cannot be tested using the context conditions available through PTC Arbortext Layout Developer or PTC Arbortext Layout Developer’s context control streams. For example, it is sometimes useful to use XPath to test for certain text content in different contexts.
The fFormatting.evaluateXPath() method is the basis for using XPath in PTC Arbortext Layout Developer through JavaScript. This method returns the string result of an XPath expression.
The fxDOM object fxNode, PTC Arbortext Layout Developer’s extension to the DOM Level 2 Node object, also includes an evaluateXPath() method. This method allows you to evaluate XPath expressions relative to that node. The result is returned in the form of an fXPathResult object.
Testing Context with XPath
XPath is particularly useful for testing the context of the current element to drive formatting. Using JavaScript, this can be used within a simple switch statement. For example:
var s = new fStyle;
var parent = formatting.evaluateXPath('local-name(..)');

switch (parent) {
case "chapter":
s.height = "25pt";
case "figure":
s.height = "10pt";
case "section":
s.height = "18pt";
s.color = "red";
s.height = "12pt";
Outputting the Result of XPath Expressions
The fFormatting.write() method allows you to display the result of the XPath expression inline. For example, this sample code displays the count of para elements at the current hierarchical level: