Generating Links in Unstructured Documents
Before we leave the topic of linking, we’ll discuss one more useful technique. So far, all of this chapter’s examples have been structured nicely. When there was a relationship between two pieces of information, we had an id
and refid
pair to match them. What happens if the XML document you’re transforming isn’t written that way? Fortunately, we can use the key()
function and a new function, generate-id()
, to create structure where there isn’t any.
An Unstructured XML Document in Need of Links
For our example here, we’ll take out all of the id
and refid
attributes that have served us well so far. This may be a contrived example, but it demonstrates how we can use the key()
and generate-id()
functions to generate links between parts of our document.
In our new sample document, we’ve stripped out the references that neatly tied things together before:
<?xml version="1.0" ?> <!DOCTYPE glossary SYSTEM "unstructuredglossary.dtd"> <glossary> <glentry> <term>applet</term> <defn> An application program, written in the Java programming language, that can be retrieved from a web server and executed by a web browser. A reference to an applet appears in the markup for a web page, in the same way that a reference to a graphics file appears; a browser retrieves an applet in the same way that it retrieves a graphics file. For security reasons, an applet's access rights are limited in two ways: the applet cannot access the file system of the client upon ...
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.