Edit online

This topic contains some guidelines for writing XPath expressions. They are used to extract the content from the merged DITA map document (this document is in HTML format if using the DITA Map PDF - based on HTML5 & CSS transformation, or in DITA XML format for the DITA Map PDF - based on DITA & CSS (WYSIWYG) transformation).

This is an example where the product name meta-information is placed before the front page title:
*[class~="front-page/front-page-title"]:before {
    text-align: left;
    content: oxy_xpath("(//*[contains(@class, 'topic/prodname')]/text())[1]");
    display:block;
}
Notes:
  • Do not use the DITA element names directly. You must use the DITA @class attribute instead, as these attributes are propagated to the merged elements (including HTML <div> elements) while the element names can be lost. By using the class selectors, you also cover DITA specializations.
  • Use the "[1]" XPath predicate to select the first value from the document. For example, oxy_xpath("(//*[contains(@class, 'topic/prodname')]/text())[1]"). The meta-information might be copied multiple times in the output, inherited by the <topicref> elements, so you can get many more values than expected.
  • Do not use strings as values for the pseudo elements content, as the string values are not supported for pseudo elements. Instead, use the XPath directly.
  • Use the Oxgyen XPath Builder view to test the XPath expressions.