<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="cond-svg.xsl" type="text/xsl"?>
<html xmlns:svg="http://www.w3.org/2000/svg"
	xmlns:dr="http://documenta.rudolphina.org/"
	xmlns="http://www.w3.org/1999/xhtml">
<!--
<!DOCTYPE html PUBLIC
	"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
	"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"
	[<!ATTLIST style dr:select CDATA #IMPLIED><!ATTLIST link dr:select CDATA #IMPLIED>]>
-->
	<head>
		<title>SVG embedded inline in XHTML</title>
		<link rel="stylesheet" href="cond-svg-css.css" type="text/css" />
		<style type="text/css">
		div.cont {
			width: 100px;
			margin-right: 16px;
			margin-bottom: 16px;
			float: left;
		}
		div.nosvg {
			height: 100px;
			border: 1px solid black;
		}
		ellipse {
			stroke: black;
			stroke-width: 1px;
			fill: url(#r_grad);
		}
		radialGradient > stop:first-child {
			stop-opacity:0;
			stop-color: #C4C4C4;
		}
		</style>
		<style type="text/css" dr:select="SVG">
		.nosvg {
			display: none;
		}
		</style>
		<style type="text/css" dr:select="IE 6">
		dt.dtwhite {
			width: 48px;
			height: 16px;
		}
		dt.dtblack {
			clear: left;
		}
		</style>
		<style type="text/css" dr:select="IE 6">div.nosvg {background-color: #6666CC} stop + stop {stop-color: #6666CC}</style>
		<style type="text/css" dr:select="IE 7">div.nosvg {background-color: #0099FF} stop + stop {stop-color: #0099FF}</style>
		<style type="text/css" dr:select="IE 8">div.nosvg {background-color: #66CCFF} stop + stop {stop-color: #66CCFF}</style>
		<style type="text/css" dr:select="FF 1">svg + div {background-color: #FF5F49}</style>
		<style type="text/css" dr:select="FF 2">stop + stop {stop-color: #FFBC2F}</style>
		<style type="text/css" dr:select="FF 3">stop + stop {stop-color: #FFED0F}</style>
		<style type="text/css" dr:select="Safari 2">svg + div {background-color: #3CB371}</style>
		<style type="text/css" dr:select="Safari 3">stop + stop {stop-color: #90DD90}</style>
		<style type="text/css" dr:select="Opera 9">stop + stop {stop-color: #CC33FF}</style>
		<style type="text/css" dr:select="Opera 9.50">stop + stop {stop-color: #FFCCFF}</style>
		<style type="text/css" dr:select="X-Smiles">svg + div {background-color: #4BFFFF}</style>
		<style type="text/css" dr:select="unknown">div.nosvg {background-color: white}</style>
		<style type="text/css" dr:select="error">div.nosvg {background-color: black}</style>
	</head>
	<body>
		<h1>Browser Detection with XSLT</h1>
		<p>Manfred Staudinger, Vienna (May 2008)</p>
		<h3>Beyond Conditional Comments and JavaScript</h3>
		<p>
			By adding an XSLT stylesheet to your XHTML you may <b>select any
			element</b> to be included or excluded per browser - even with JavaScript
			disabled. Obvious canditates for being selected are the &lt;style>, &lt;link> and
			&lt;script> elements.
		</p>
		<p>
			For the categories offered, XSLT browser detection is more reliable and
			standards conformant than CSS hacks or JavaScript browser detection. But its
			only to complement not to substitute well known methods, like JavaScripts object
			detection and CSS's progressive enhancement method, which both work at a
			much finer granularity. <br/>Demo:
		</p>
		<div class="cont">
			<svg:svg version="1.1" baseProfile="full" width="100px" height="100px">
				<svg:defs>
					<svg:radialGradient id="r_grad" cx="20%" cy="50%" r="50%" fx="50%" fy="50%">
						<svg:stop offset="0%"/>
						<svg:stop offset="100%"/>
					</svg:radialGradient>
				</svg:defs>
				<svg:ellipse cx="50" cy="50" rx="35" ry="49"/>
			</svg:svg>
			<div class="nosvg"/>
		</div>
		<p>Browser Selection: <span class="browser"></span></p>
		<p>If SVG is enabled the shape becomes an ellipse, otherwise a square; the color will
		change for different browsers.</p>
		<dl>
			<dt style="background-color: #6666CC"></dt><dd>IE 6, IE, SVG (only via ASV)</dd>
			<dt style="background-color: #0099FF"></dt><dd>IE 7, IE, SVG (only via ASV)</dd>
			<dt style="background-color: #66CCFF"></dt><dd>IE 8, IE (beware: IE 8 beta, 8.0.6001.17184, incorrect)</dd>
			<dt style="background-color: #FF5F49"></dt><dd>Firefox 1 (1.0+), FF 1, Firefox, Gecko 1.7, Mozilla 1.7, Camino 0.8, Camino, Netscape (7, 8)</dd>
			<dt style="background-color: #FFBC2F"></dt><dd>Firefox 2 (1.5+, 2.0+), FF 2, Firefox, Gecko 1.8, SeaMonkey 1, SeaMonkey, Camino 1, Camino, Epiphany 2.14, Epiphany 2.20, Epiphany, Flock (1.0.9, 1.1.2), K-Meleon (1.1.4), Kazehakase (0.4.3, 0.5.2), Netscape (9), SVG</dd>
			<dt style="background-color: #FFED0F"></dt><dd>Firefox 3, FF 3, Firefox, Gecko 1.9, SeaMonkey 2, SeaMonkey, Camino 2, Camino, Epiphany 2.22, Epiphany, Minefield (3.0), SVG</dd>
			<dt style="background-color: #3CB371"></dt><dd>Safari 1 (1.3+), Safari 2 (2.0.2+), Safari</dd>
			<dt style="background-color: #90DD90"></dt><dd>Safari 3 (SVG for 3.0?), Safari, SVG</dd>
			<dt style="background-color: #CC33FF"></dt><dd>Opera 9, Opera, SVG</dd>
			<dt style="background-color: #FFCCFF"></dt><dd>Opera 9.50, Opera, SVG</dd>
			<dt style="background-color: #4BFFFF"></dt><dd>X-Smiles</dd>
			<dt class="dtwhite" style="background-color: white"></dt><dd>Unknown browser<span class="vendor"></span></dd>
			<dt class="dtblack" style="background-color: black"></dt><dd>Error: no XSL-transformation!</dd>
		</dl>
		<h3>Prerequisites</h3>
		<p>
			Get the "cond-svg-html.xsl" stylesheet, add a processing instruction to your XHTML
			and declare the namespace prefix "dr" on the head element. Optionally, if you
			want to easily use the W3C Validator, add the attribute definitions just before
			the end of the DOCTYPE.
		</p>
		<ul>
			<li>&lt;?xml-stylesheet href="cond-svg-html.xsl" type="text/xsl"?></li>
			<li>&lt;head xmlns:dr="http://documenta.rudolphina.org/"></li>
			<li>[&lt;!ATTLIST link dr:select CDATA #IMPLIED>
				&lt;!ATTLIST style dr:select CDATA #IMPLIED>]</li>
			<li>serve the XHTML as application/xml or text/xml</li>
		</ul>
		<h3>Selection</h3>
		<p>
			To include a html or any other element for one of the above choices you use the
			<b>dr:select</b> attribute and specify one or more tokens as a comma
			separated list. For example dr:select="Firefox, Safari 3" will cause the element
			to be included for any Firefox and for Safari 3. If you specify more than one
			token, each of which constitutes a positive selection, you may use any
			combination of tokens from the non-IE browsers plus the token "IE".
		</p>
		<p>
			To select a specific IE only one token in the <b>dr:select</b> attribute is
			allowed, because it is directly used in constructing a Conditional Comment
			(CC). These are constructed on the fly only if the current browser is actually
			an IE. Any valid CC expression is allowed, so you can specify for example
			dr:select="lte IE 7" (positive selection) or dr:select="!IE 6" (negative selection).
			To clarify, a positive CC selection will allow only the IE's specified to read the
			CSS, and a negative CC will exclude them from seeing it.
		</p>
		<p>
			Elements with a <b>dr:select</b> attribute will be copied for the appropriate
			browser, but without that attribute. Other elements remain unchanged.
		</p>
		<h3>Inline SVG and ASV</h3>
		<p>
			To take full advantage of this approach, you should consider to delete all
			the various <b>style attributes</b> and move the styles to one common
			<b>style element</b>.
		</p>
		<p>
			While native SVG implementations do support SVG styles anywhere in the
			CSS cascade, specfically in external files designated by &lt;link> elements,
			ASV does support external CSS files only via an XML stylesheet, which is not
			available in case of inline SVG.
		</p>
		<p>
			If ASV is detected (currently checked with JScript for IE only), the necessary
			object element and the import PI are created in the head section. Further all the
			style elements applicable for the browser are copied into newly created
			&lt;svg:style> elements within the &lt;svg:defs>.
		</p>
		<p>
			The namspace prefix "svg" which is used for all the SVG elements could be
			eliminated by declaring a default namspace. But ASV depends on the prefix,
			not on the namespace.
		</p>
		<p>
			From the demo it is obvious that ASV supports advanced CSS selectors while
			IE 6 does not.
		</p>
		<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"/>
		<script type="text/javascript">_uacct="UA-534617-5";_uflash=0;urchinTracker();</script>
	</body>
</html>
