The xlink:show Attribute

The xlink:show Attribute

You use the XLink xlink:show attribute to indicate how you want the linked-to resource displayed when the link is activated. The xlink:show attribute has five values that are predefined:

  • embed Embeds the linked-to resource in the current resource.

  • new Opens a new display area, such as a new window, to display the new resource.

  • none Does not show the resource. (It can also mean that the application's behavior is not constrained by this markup.)

  • other Indicates some setting other than those that are predefined (and usually means that the application should refer to other markup for more information).

  • replace Replaces the current resource, in the same window, if there is one.

Even though xlink:show has these predefined values, you can set your own values.

The default behavior of HTML links is to navigate to a linked-to document, replacing the current document with the new one. You can mimic that operation by assigning xlink:show a value of "replace" :

 <MOVIE_REVIEW xmlns:xlink = "http://www.w3.org/1999/xlink"      xlink:type = "simple"  xlink:show = "replace"  xlink:href="http://www.starpowdermovies.com/reviews.xml">     Mr. Blandings Builds His Dream House </MOVIE_REVIEW> 

In practice, this is application-specific. Although you'd expect the current document to be replaced with a new one, there are plenty of other possibilities. For example, a spreadsheet application may replace the displayed data, but not the overall display, with data from the linked-to resource. Or, the xlink:show attribute can make the application use a different stylesheet when the link is activated. Once again, the actual implementation is up to the software designer.

If the value of xlink:show is "new" , activating the link typically opens a new window that displays the linked-to resource:

 <MOVIE_REVIEW xmlns:xlink = "http://www.w3.org/1999/xlink"      xlink:type = "simple"  xlink:show = "new"  xlink:href="http://www.starpowdermovies.com/reviews.xml">     Mr. Blandings Builds His Dream House </MOVIE_REVIEW> 

However, as before, there are plenty of possibilities. A value of "new" might simply mean that a new column is added to a table or that a new line displayed in a graph. It's a good idea to be considerate here. Bear in mind that users coming from HTML will not be used to having links that automatically open new windows , if that's what your link is going to doyou might make sure that you add some explanatory text because otherwise such behavior might be annoying.

Similarly, the attribute value "embed" is subject to interpretation. The idea here is that when a link is activated, the linked-to resource is embedded in the current display or document, although what is actually embedded and how this is done is up to the application. For example, say that we linked to our planetary example, which I'll call ch15_06.xml here for the sake of reference:

Listing ch15_06.xml
 <?xml version="1.0"?> <PLANETS>     <PLANET>         <NAME>Mercury</NAME>         <MASS UNITS="(Earth = 1)">.0553</MASS>         <DAY UNITS="days">58.65</DAY>         <RADIUS UNITS="miles">1516</RADIUS>         <DENSITY UNITS="(Earth = 1)">.983</DENSITY>         <DISTANCE UNITS="million miles">43.4</DISTANCE><!--At perihelion-->     </PLANET>     <PLANET>         <NAME>Venus</NAME>         <MASS UNITS="(Earth = 1)">.815</MASS>         <DAY UNITS="days">116.75</DAY>         <RADIUS UNITS="miles">3716</RADIUS>         <DENSITY UNITS="(Earth = 1)">.943</DENSITY>         <DISTANCE UNITS="million miles">66.8</DISTANCE><!--At perihelion-->     </PLANET>     <PLANET>         <NAME>Earth</NAME>         <MASS UNITS="(Earth = 1)">1</MASS>         <DAY UNITS="days">1</DAY>         <RADIUS UNITS="miles">2107</RADIUS>         <DENSITY UNITS="(Earth = 1)">1</DENSITY>         <DISTANCE UNITS="million miles">128.4</DISTANCE><!--At perihelion-->     </PLANET> </PLANETS> 

Here's how the links to the various planets might look. I'm anticipating the use of XPointers here to pick out the specific planets in ch15_06.xml. Note that the xlink:show values are all "embed" here:

Listing ch15_07.xml
 <?xml version = "1.0"> <ASTRO_NEWS>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "simple"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 1]">         Mercury     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "simple"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 2]">         Venus     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "simple"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 3]">         Earth     </PLANET_DATA> <ASTRO_NEWS> 

After all these links are activated, the data from the various <PLANET> elements might be inserted into the current display, something like this (again, the details are up to the host application):

 <?xml version = "1.0">  <ASTRO_NEWS>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         <NAME>Mercury</NAME>         <MASS UNITS="(Earth = 1)">.0553</MASS>         <DAY UNITS="days">58.65</DAY>         <RADIUS UNITS="miles">1516</RADIUS>         <DENSITY UNITS="(Earth = 1)">.983</DENSITY>         <DISTANCE UNITS="million miles">43.4</DISTANCE><!--At perihelion-->     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         <NAME>Venus</NAME>         <MASS UNITS="(Earth = 1)">.815</MASS>         <DAY UNITS="days">116.75</DAY>         <RADIUS UNITS="miles">3716</RADIUS>         <DENSITY UNITS="(Earth = 1)">.943</DENSITY>         <DISTANCE UNITS="million miles">66.8</DISTANCE><!--At perihelion-->     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         <NAME>Earth</NAME>         <MASS UNITS="(Earth = 1)">1</MASS>         <DAY UNITS="days">1</DAY>         <RADIUS UNITS="miles">2107</RADIUS>         <DENSITY UNITS="(Earth = 1)">1</DENSITY>         <DISTANCE UNITS="million miles">128.4</DISTANCE><!--At perihelion-->     </PLANET_DATA> <ASTRO_NEWS> 

You can also set xlink:show to a value of "other" , in which case you're indicating to the application that your markup is not constraining this attribute (which usually means that the application should refer to other markup). In fact, it's up to the application to decide what happens because it may ignore any of the values that you carefully assign to xlink:show , especially if it's not capable of handling what you want (as when you set xlink:show to "new" in a browser that can't handle multiple windows). The xlink:show value of "none" usually is an instruction not to show the associated resource (although it can also mean that the application's behavior is not constrained by this markup).

You're also free to set xlink:show to your own values. For example, setting it to "new_row" might add a new row to a table to display data in. You might also use this attribute to indicate something about the format in which documents are displayed rather than how they are displayed, as when you set xlink:show to the name of a stylesheet. Or, you might set JavaScript code to execute in this attribute's value when the link is activated.

Don't forget that you need to declare xlink:show if you want to create valid documents. That might look something like this in a DTD:

 <!ELEMENT ASTRO_NEWS>  <!ATTLIST ASTRO_NEWS     xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink"     xlink:type CDATA #FIXED "simple"     xlink:href CDATA #REQUIRED     xlink:show (new  replace  embed  none  other) #IMPLIED "replace"> 


Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net