A Complete XLink Example

I've mentioned a few times throughout this lesson how XLink has unfortunately yet to garner much support in major web browsers. That's the bad news. The good news is that the Firefox browser does include support for simple XLink links. You can create links in Firefox using XLink that approximate the same links supported in HTML. In other words, you can't create extended links or embedded links, which is somewhat of a bummer. Listing 22.2 contains the code for a Top Five movie list XML document that makes use of simple XLink links.

Listing 22.2. The Top Five Sample XML Document
 1: <?xml version="1.0"?>
 2: <?xml-stylesheet type="text/css" href="topfive.css"?>
 4: <topfive xmlns:xlink="http://www.w3.org/1999/xlink">
 5:   <title>Top Five Movies</title>
 7:   <intro>Following are my top five favorite movies:</intro>
 9:   <item>
10:     1. <itemLink xlink:type="simple" xlink:show="replace"
11:     xlink:actuate="onRequest" xlink:title="Number 1"
12:     xlink:href="http://www.amazon.com/exec/obidos/ASIN/B00004TDTO/">
13:     Jaws</itemLink>
14:   </item>
16:   <item>
17:     2. <itemLink xlink:type="simple" xlink:show="replace"
18:     xlink:actuate="onRequest" xlink:title="Number 2"
19:     xlink:href="http://www.amazon.com/exec/obidos/ASIN/6305499128/">
20:     Raising Arizona</itemLink>
21:   </item>
23:   <item>
24:     3. <itemLink xlink:type="simple" xlink:show="replace"
25:     xlink:actuate="onRequest" xlink:title="Number 3"
26:     xlink:href="http://www.amazon.com/exec/obidos/ASIN/B00003CWTI/">
27:     Magnolia</itemLink>
28:   </item>
30:   <item>
31:     4. <itemLink xlink:type="simple" xlink:show="replace"
32:     xlink:actuate="onRequest" xlink:title="Number 4"
33:     xlink:href="http://www.amazon.com/exec/obidos/ASIN/0767821408/">
34:     Bottle Rocket</itemLink>
35:   </item>
37:   <item>
38:     5. <itemLink xlink:type="simple" xlink:show="replace"
39:     xlink:actuate="onRequest" xlink:title="Number 5"
40:     xlink:href="http://www.amazon.com/exec/obidos/ASIN/B000286RKW/">
41:     GoodFellas</itemLink>
42:   </item>
44:   <conclusion>To find out more about me, please feel free to visit
45:   <popupLink xlink:type="simple" xlink:show="new"
46:   xlink:actuate="onRequest" xlink:title="xyz.com"
47:   xlink:href="http://www.xyz.com/">
48:   my Web site</popupLink>.
49:   </conclusion>
50: </topfive>

This code consists of six different links: five for the top five movies and one as a contact link near the bottom of the document. The movie links all link to Amazon.com, whereas the contact link directs you to my web site. The movie links all have their show attributes set to replace, which means the linked resource is opened in the same window as (replaces) the original document. The contact link is slightly different in that its show attribute is set to new (line 45), which means the linked resource is opened in a new window. The actuate attribute for all of the links is set to onRequest (line 46), which requires the user to click the links in order for them to be navigated. Figure 22.5 shows the Top Five movie document as viewed in Firefox.

Figure 22.5. The Top Five sample document provides an example of how simple XLink links can be used in an XML document.

You may be wondering how the browser knows to underline the links. There isn't anything magical going on here. I just neglected to show you the CSS stylesheet that is responsible for styling the Top Five document.