context sensitive highlighting
context highlighting refers to alterations in the appearance of
webpages based on the page currently being displayed. a typical
example is context sensitive menu generation, i.e., the
highlighting of menu items when particular pages are visible. for
example when viewing development related pages on this website a
dashed box appears around the development menu block on the left
hand side.
two components are required for context highlighting to work.
the first is "context awareness" of the page being displayed (e.g.,
a development page on this website must know that it belongs to the
development section). the second is "context recognition" within
the menu itself - it must know which elements to alter when a
particular page context is encountered (e.g., so as to place a
dashed box around the development menu block and not around some
other block.) the former can be automated but the latter reflects a
highlighting policy that must be stated by the webmaster in the
menu file.
to support context highlighting the librapple.xsl (and
librapple.conf.xsl) provides templates to implement the necessary
transformations. simply include the librapple.xsl in your website
XSLT and call the librapple_generateMenu template passing it the
value of the file in which your menu system is defined. the menu
file, detailed below, is a separate file that is processed as the
website XSLT parses each input file. the following skeleton website
XSLT uses the file "menu.html" located in the same directory as the
XSLT itself:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet ... >
....
<!-- top level include directive (sablotron requires "file://"
protocol - see faq for details) -->
<xsl:include href="librapple.xsl" >
....
<!-- root template -->
<xsl:template match="/" >
....
<!-- point in your website XSLT at which you wish to invoke the
menu -->
<xsl:call-template name="librapple_generateMenu" >
<!-- note the use of single quotes in the select attribute!
-->
<xsl:with-param name="menuFile" select="'menu.html'" />
</xsl:call-template>
....
</xsl:template>
....
</xsl:stylesheet>
context awareness is conveyed by including a <meta>
element in the document <head> of the input file. the
<meta> element has the following format:
<meta name="rapple_pageContext"
content="label" />
and may appear at most once in the document head. the value of
the "content" attribute is arbitrary. the following is an example
of an input document with "devel" page context
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:rpl="http://rapple.sourceforge.net/2005/xhtml" >
<head>
<title>my input file</title>
<meta name="rapple_pageContext" content="devel" />
</head>
<body>
<h1>welcome to the development section</h1>
.... document contents ...
</body>
<html>
context recognition requires applying "menuCtxt" attributes to
elements of the menu. since these are not HTML attributes they
belong to a special rapple namespace,
"http://rapple.sourceforge.net/2005/xhtml", which is usually
associated with the prefix "rpl". whenever a menu element bears
such an attribute a check is made to see if its value coincides
with the input page context. if a match occurs then a "class"
attribute is added to the element with an in-context value,
otherwise an out-context is used. you can define appropriate class
names in each case by editing the librapple.conf.xsl file (the
default values are "rappleMenuInFocus" resp. "rappleMenuOutFocus").
if a menu element does not have a "menuCtxt" attribute then it
remains unaltered.
the menu file can be an ordinary XHTML file as the
librapple_generateMenu template is effective only on children of
its <body> element. since the menu file is an input file of
your XSLT website (loaded using the XSLT document() function by a
template in librapple.xsl) references to the $host variable cannot
normally be resolved. librapple.xsl takes care of this, however, by
performing the necessary substitutions so that it appears that all
references are resolved. the following is a sample menu file with
context recognition of "devel" and "help" contexts:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:rpl="http://rapple.sourceforge.net/2005/xhtml" >
<head><title>my menu
file</title></head>
<body>
site menu (<a
href="{$host}index.html">homepage</a>)
<table border="0" padding="2" rpl:menuCtxt="devel">
...development section menu...
</table>
<table border="0" padding="2" rpl:menuCtxt="help">
...help section menu...
</table>
</body>
<html>
context recognition permits arbitrary markup for your menu
system but does require that changes in appearance be implemented
using CSS classes alone. you must therefore ensure that your site
CSS contains in-context and out-context classes that correspond to
the $librapple.css.context.infocus resp.
$librapple.css.context.outfocus in your librapple.conf.xsl file (by
default these classes are called "rappleMenuInFocus" resp.
"rappleMenuOutFocus"). for example the following CSS classes define
red background colour for in-context and green for out-context
elements:
.rappleMenuInFocus { background-color: #FF0000
}
.rappleMenuOutFocus { background-color: #00FF00 }
the effect of all this is that if the website XSLT encounters an
input document with "devel" page context then menu elements that
recognise the "devel" context are classified as in-context whilst
all other menu elements are either unaffected or are classified as
out-context as appropriate. for example, using the default context
classes the generated menu becomes:
site menu (<a
href="{$host}index.html">homepage</a>)
<table border="0" padding="2" class="rappleMenuInFocus"
rpl:menuCtxt="devel">
...development section menu...
</table>
<table border="0" padding="2" class="rappleMenuOutFocus"
rpl:menuCtxt="help">
...help section menu...
</table>
|