Chapter 5. Creating Links and Cross-References
If you’re creating a web site, publishing a book, or creating an XML transaction, chances are many pieces of information will refer to other things. This chapter discusses a several ways to link XML elements. It reviews three techniques:
Using the
id()
functionDoing more advanced linking with the
key()
functionGenerating links in unstructured documents
Generating Links with the id() Function
Our first attempt at linking will be with the XPath id()
function.
The ID, IDREF, and IDREFs Datatypes
Three of the basic datatypes supported by XML Document Type Definitions (DTDs) are ID
, IDREF
, and IDREFS
. Here’s a simple DTD that illustrates these datatypes:
<!--glossary.dtd--> <!--The containing tag for the entire glossary--> <!ELEMENT glossary (glentry+) > <!--A glossary entry--> <!ELEMENT glentry (term,defn+) > <!--The word being defined--> <!ELEMENT term (#PCDATA) > <!--The id is used for cross-referencing, and the xreftext is the text used by cross-references.--> <!ATTLIST term id ID #REQUIRED xreftext CDATA #IMPLIED > <!--The definition of the term--> <!ELEMENT defn (#PCDATA | xref | seealso)* > <!--A cross-reference to another term--> <!ELEMENT xref EMPTY > <!--refid is the ID of the referenced term--> <!ATTLIST xref refid IDREF #REQUIRED > <!--seealso refers to one or more other definitions--> <!ELEMENT seealso EMPTY> <!ATTLIST seealso refids IDREFS #REQUIRED >
In this DTD, each <term>
element is required to have an id
attribute, ...
Get XSLT now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.