9. Cross-references

A cross-reference from one part of a document to another part of a document, including a section number, can be generated automatically using CSS, thus reducing the risk for error when creating these references.

To create a cross-reference dynamically, use CSS the properties target-counter and target-text to add content to an internal link.

Example: adding the section number and page number to a link.

a:before { 
	content: '"Chapter ' target-counter(attr(href), chapter) ': ';
}
a:after {
	content:  '" (p. ' target-counter(attr(href), page) ')';
}

Using this style declaration, the hyperlink "Page Margin Boxes" is rendered as "Chapter 5: Page Margin Boxes" (p. 37)".

Note that cross references can only be resolved for internal links refering to an anchor in the same document, see the chapter ??? for more information.

The target-counter function can be used in the same way as the counter(), the difference being that it retrieves the value of a counter at the end of a link. The required attributes for target-counter are the name of the link attribute to follow ("href" for hyperlinks in HTML), and the name of the counter to retrieve. An optional third argument can be added to control the formatting of the counter when it is displayed.

The target-text function is used to create textual cross-references, and retrieve the textual content of an element a link refers to. The function has two arguments, but only the first is required. The first argument the name of the link attribute to follow. The second argument is optional and indicates which content is retrieved. PDFreactor supports the following values defined in CSS 3 for the second argument:

content - retrieves the textual content of the element.

first-letter - retrieves only the first letter of the textual content of the element.