Macro Language Reference > PIs > Formatting Instructions > xpath
  
xpath
Description
This command is used to call XPath statements within PTC ALD.
XPath can be used in PTC ALD to query and return parts of a document as inline commands, in show strings or in scripts. It is possible to use XPath inline to display the results of the expression and to pass information to variables and tags using the normal PTC ALD syntax.
 
Example 389. Retrieve the text in the second child tag using an XPath expression
<authors>
<firstname>Bob</firstname>
<surname>Harris</surname>
<firstname>Fred</firstname>
<surname>Mitchell</surname>
</authors>
<?xpath string(/authors/surname[2])>
The above syntax retrieves the text in the second child element; in this case the surnames of the authors.
Syntax
<?xpath xpath_expression:b>
xpath_ expression
A valid XPath expression
Additional Information
Using the simple syntax outlined above will output the result of the expression at the point in the stream where the expression is placed. The result of an expression can be assigned to a variable or string in the same way as it would be with show strings, by placing the target before the expression. For example:
<?xpath ^"string" expression>
This example will pass the result of the XPath expression to a variable called string.
XPath and XPointer expressions can also contain the stream name and context node position, as shown in the three examples below:
stream#xpath
stream#context char pos#xpath
stream#-context
node id#xpath
For more information, see Reference Chapter: XPath in PTC ALD, Reference Chapter: XML in PTC ALD, and Reference Chapter: XSLT in PTC ALD.
Related Links