<?xml version="1.0"?>
<!--
$Id: characters.xsl,v 1.13 2008/04/23 21:09:28 dcarlis Exp $

mml6.xsl David Carlisle
Generate bycodes.html, byalpha.html and the alphabetic glyph tables
originally for MathML chapter 6.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		version="2.0"
		xmlns:d="data:,dpc"
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
		exclude-result-prefixes="d xs">

<xsl:import href="xmlspec.xsl"/>

<xsl:output encoding="US-ASCII" omit-xml-declaration="yes"/>

<xsl:param name="cssbase" select="'http://www.w3.org/StyleSheets/TR/'"/>
<xsl:param name="baseuri" select="'http://www.w3.org/2003/entities/'"/>
<xsl:param name="resultbase" select="'../2007doc/'"/>
<xsl:param name="editors-copy" select="''"/>

<xsl:variable name="css" as="element()">
    <link rel="stylesheet" type="text/css" href="{$cssbase}W3C-WD.css"/>
</xsl:variable>

<xsl:template name="css">
  <xsl:copy-of select="$css"/>
</xsl:template>

<xsl:param name="glyphs" select="'http://www.w3.org/2003/entities/glyphs'"/>

<xsl:strip-space elements="group"/>


<xsl:variable name="u" select="doc('../2007xml/unicode.xml')"/>
<xsl:variable name="blocks" select="$u/unicode/unicodeblocks/block"/>
<xsl:variable name="hex" select="('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F')"/>
<xsl:key name="set" match="entity" use="@set"/>
<xsl:key name="id" match="character" use="@id"/>



<xsl:template match="/">
  <xsl:result-document 
      method="html"
      encoding="iso-8859-1"
      doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
      doctype-system="http://www.w3.org/TR/html4/loose.dtd"
      href="{$resultbase}overview.html">
    <xsl:apply-templates/>
  </xsl:result-document>
  <xsl:apply-templates select="$u/unicode/entitygroups/group[@name='2007']/set"/>
  <xsl:apply-templates select="$u/unicode/charlist"/>
</xsl:template>

<xsl:variable name="blockstarts" select="('000','001','002','003','004',
                       '020','021','022','023','024','025','026','027','029','02A',
                       '0FB','0FE',
                       '1D4','1D5','1D6','1D7')"/>


<xsl:template match="charlist">



<xsl:for-each select="$blockstarts">
  <xsl:call-template name="code-chart">
    <xsl:with-param name="range" select="."/>
  </xsl:call-template>
</xsl:for-each>


<xsl:call-template name="bycodes"/>
<xsl:call-template name="byalpha"/>


</xsl:template>



<xsl:template match="group[@name='predefined']"/>

<xsl:template match="group">
<xsl:result-document method="html" 
		     encoding="iso-8859-1"
     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
     doctype-system="http://www.w3.org/TR/html4/loose.dtd"
     href="{$resultbase}/overview-{@name}.html">
<html>
<head>
<title><xsl:value-of select="@name"/></title>
</head>
<body>
<h1><xsl:value-of select="@name"/></h1>
<p>
<a href="../overview.html">Contents</a>
</p>
<table>
<tr>
<td>&#160;</td>
<td>&#160;</td>
<td>&#160;</td>
<td>&#160;<a href="../{@name}/{@name}map.xsl">XSLT 2 draft character map</a>&#160;</td>
</tr>
<xsl:for-each select="set">
<xsl:variable name="f">
<xsl:apply-templates select="." mode="name"/>
</xsl:variable>
<xsl:if test="string($f)">
<tr>
<th><xsl:value-of select="$f"/></th>
<td>&#160;<a href="{$f}.html">HTML Description</a>&#160;</td>
<td>&#160;<a href="{$baseuri}{../@name}/{$f}.ent">Entity Declarations</a>&#160;</td>
<td>&#160;<a href="{$baseuri}{../@name}/{$f}map.xsl">XSLT 2 draft character map</a>&#160;</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:result-document>
<xsl:apply-templates select="set[not(../@name='mathml') or starts-with(@name,'m')]"/>
</xsl:template>

<xsl:template match="set" mode="name">
<xsl:choose>
<xsl:when test="../@name='mathml' and not(starts-with(@name,'m'))"/>
<xsl:when test="starts-with(@name,'957')"><xsl:value-of select="substring(@name,11)"/></xsl:when>
<xsl:when test="starts-with(@name,'88')"><xsl:value-of select="substring-after(@name,'-')"/></xsl:when>
<xsl:when test="starts-with(@name,'html')"><xsl:value-of select="substring-after(@name,'-')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="@name"/></xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="set"/>
<xsl:template match="group[@name='2007']/set">
<xsl:variable name="set" select="@name"/>
<xsl:variable name="f">
<xsl:apply-templates select="." mode="name"/>
</xsl:variable>
<xsl:variable name="t"
  select="upper-case($f)"/>

<xsl:result-document method="html" 
		     encoding="iso-8859-1"
     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
     doctype-system="http://www.w3.org/TR/html4/loose.dtd"
     href="{$resultbase}{$f}.html">
<html>
<head>
<title><xsl:value-of select="$t"/></title>
<style type="text/css">
.ignore {background-color: #AAAAAA;}
</style>
<xsl:copy-of select="$css"/>
</head>
<body>
<h1><xsl:value-of select="$t"/></h1>
<p>
<a href="overview.html">Contents</a>
<xsl:variable name="p">
 <xsl:apply-templates select="preceding-sibling::set[1]" mode="name"/>
</xsl:variable>
<xsl:variable name="n">
 <xsl:apply-templates select="following-sibling::set[1]" mode="name"/>
</xsl:variable>

<xsl:if test="string($p)">
<br/>Previous: <a href="{$p}.html">
<xsl:value-of select="$p"/></a>
</xsl:if>
<xsl:if test="string($n)">
<br/>Next: <a href="{$n}.html">
<xsl:value-of select="$n"/></a>
</xsl:if>
</p>
<p>
<a href="{$baseuri}{../@name}/{$f}.ent">Entity Declarations</a><br/>
<a href="{$baseuri}{../@name}/{$f}map.xsl">XSLT 2 draft character map</a>
</p>
<table border="1">
<tr>
<th>Name</th>
<th>Unicode</th>
<th>Glyph</th>
<th>Unicode Name</th>
<th>Description</th>
<th>Aliases</th>
</tr>
<xsl:for-each select="key('set',$set)">
<xsl:sort lang="en" select="@id"/>
<tr>
    <xsl:if test="../description/@unicode='provisional'">
      <xsl:attribute name="class">provisional</xsl:attribute>
      <xsl:message><xsl:value-of select="concat('Provisional: ',$set,': ',@id)"/></xsl:message>
    </xsl:if>
    <xsl:if test="@optional and @default='IGNORE'">
      <xsl:attribute name="class">ignore</xsl:attribute>
    </xsl:if>
<td>
<xsl:value-of select="@id"/>
</td>
<td>
<xsl:value-of select="substring(../@id,2)"/>
</td>
<td>
<img height="32" 
         width="32"
         src="{$glyphs}/{substring(../@id,2,3)}/{translate(../@id,'x','')}.png"
         alt="{../@id}"
         >
<xsl:if test="../@image='none'"><xsl:attribute
  name="src"><xsl:value-of select="$glyphs"/>/none.png</xsl:attribute></xsl:if>
</img>
</td>
<td>
<xsl:value-of select="../description"/>
</td>
<td>
<xsl:value-of select="desc"/>
<xsl:if test="not(desc)">&#160;</xsl:if>
</td>
<td>
<xsl:if test="not(../entity[@set='mmlalias'] or ../entity[@set=$set][2])">&#160;</xsl:if>
<xsl:for-each select="../entity[@set='mmlalias' or (@set=$set
     and @id!=current()/@id)]/@id">
<xsl:value-of select="."/>
<xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:result-document>
</xsl:template>

<!-- -->



<!-- -->

<xsl:template name="code-chart">
 <xsl:param name="range"/>
<xsl:result-document method="html" 
		     encoding="iso-8859-1"
     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
     doctype-system="http://www.w3.org/TR/html4/loose.dtd"
     href="{$resultbase}{$range}.html">
<html>
<head>
<title>Unicode Characters:
<xsl:value-of select="concat($range,'00 to ',$range,'FF')"/>
</title>
<style type="text/css">
.unassigned { background-color: #FF9999 }
.undescribed { background-color: #FFFF99 }
.proposed { background-color: #FF99FF }
span.stix {
 font-size: 125%;
 font-family: STIXGeneral, STIXGeneral-Italic, STIXGeneral-Bold, STIXGeneral-BoldItalic;
 background-color: #FFFFDD; 
}
<!--
span.cambria {
 font-family:  Cambria;
 background-color: #FFFFEE; 
}
-->
</style>
<xsl:copy-of select="$css"/>
</head>
<body>
<h1>Unicode Characters:
<xsl:value-of select="concat($range,'00 to ',$range,'FF')"/>
</h1>
<p>
<xsl:variable name="p" select="position()"/>
<a href="overview.html">Contents</a><br/>
<xsl:if test="$p!=last()">
<a href="{$blockstarts[$p+1]}.html">Next: <xsl:value-of 
select="$blockstarts[$p+1]"/>00 to  <xsl:value-of 
select="$blockstarts[$p+1]"/>FF</a><br/>
</xsl:if>
<xsl:if test="$p!=1">
<a href="{$blockstarts[$p - 1]}.html">Previous: <xsl:value-of 
select="$blockstarts[$p - 1]"/>00 to  <xsl:value-of 
select="$blockstarts[$p - 1]"/>FF</a><br/>
</xsl:if>


</p>


<table border="1">
<tr>
<th>&#160;</th>
<xsl:for-each select="$hex">
<xsl:variable name="r" select="."/>
<xsl:variable name="b" select="$blocks[@start=concat($range,$r,'0')]"/>
<xsl:variable name="e" select="d:hexfromstring(concat($range,'FF'))"/>
<xsl:choose>
<xsl:when test="$b">
  <xsl:variable name="c" select="$b/((1+min(($e,d:hexfromstring(@end))) - d:hexfromstring(@start))idiv 16)"/>
  <xsl:choose>
    <xsl:when test="$c=1">
      <th><a href="http://www.unicode.org/charts/PDF/U{$b/replace(@start,'^0','')}.pdf"><xsl:value-of select="replace($b/@name,'(([a-zA-Z][A-Za-z])|-)','&#x200b;$1')"/></a></th>
    </xsl:when>
    <xsl:otherwise>
      <th colspan="{$c}"><a href="http://www.unicode.org/charts/PDF/U{$b/replace(@start,'^0','')}.pdf"><xsl:value-of select="$b/@name"/></a></th>
    </xsl:otherwise>
  </xsl:choose>
</xsl:when>
<xsl:when test="position()=1 and not($b)">
<xsl:variable name="b" select="$blocks[@end&gt;concat($range,$r,'0')][1]"/>
<xsl:variable name="c" select="$b/((1+min(($e,d:hexfromstring(@end))) - d:hexfromstring(concat($range,$r,'0')))idiv 16)"/>
  <xsl:choose>
    <xsl:when test="$c=1">
      <th><a href=" http://www.unicode.org/charts/PDF/U{$b/replace(@start,'^0','')}.pdf"><xsl:value-of select="replace($b/@name,'(([a-zA-Z][a-zA-Z])|-)','&#x200b;$1')"/></a></th>
    </xsl:when>
    <xsl:otherwise>
      <th colspan="{$c}"><a href="http://www.unicode.org/charts/PDF/U{$b/replace(@start,'^0','')}.pdf"><xsl:value-of select="$b/@name"/></a></th>
    </xsl:otherwise>
  </xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<th>&#160;</th>
</tr>
<tr>
<th>&#160;</th>
<xsl:for-each select="$hex">
  <th><xsl:value-of select="$range"/><xsl:value-of select="."/></th>
</xsl:for-each>
<th>&#160;</th>
</tr>
<xsl:for-each select="$hex">
  <xsl:call-template name="table-row">
    <xsl:with-param name="range" select="$range"/>
    <xsl:with-param name="row" select="."/>
  </xsl:call-template>
</xsl:for-each>
<tr>
<th>&#160;</th>
<xsl:for-each select="$hex">
  <th><xsl:value-of select="$range"/><xsl:value-of select="."/></th>
</xsl:for-each>
</tr>
</table>

<h2 id="key">Key</h2>


<table border="1">
<tr><th>Cell Style</th><th>Status</th></tr>
<tr><td>&#160;&#160;&#160;</td><td>Unicode Character (Unicode 5.1)</td></tr>
<!--
<tr><td class="proposed">&#160;&#160;&#160;</td><td><a href="http://unicode.org/alloc/Pipeline.html">Proposed Unicode Character</a></td></tr>
-->
<tr><td class="unassigned">&#160;</td><td>Unicode or XML Non-Character</td></tr>
<tr><td class="undescribed">&#160;</td><td>XML Character not currently described in Unicode</td></tr>
<tr><td><img src="{$glyphs}/none.png" alt="none"/></td><td>Character for which an image is not currently available</td></tr>
<tr><td><span class="stix">&#160;X&#160;</span></td><td>Character styled with the <a href="http://www.stixfonts.org">STIX Fonts</a></td></tr>
</table>

<p>Table headings link to the (PDF) Code charts at the <a href="http://www.unicode.org">Unicode site</a>.</p>
<p>Images link to the listing <a href="bycodes.html">listing of all characters assigned an entity name</a> whenever such an entity is defined.</p>
</body>
</html>
</xsl:result-document>
</xsl:template>

<xsl:template name="table-row">
  <xsl:param name="range"/>
  <xsl:param name="row"/>
  <tr>
    <th><xsl:value-of select="$row"/></th>
    <xsl:for-each select="$hex">
      <xsl:call-template name="table-cell">
	<xsl:with-param name="range" select="$range"/>
	<xsl:with-param name="h" select="concat(.,$row)"/>
      </xsl:call-template>
    </xsl:for-each>
    <th><xsl:value-of select="$row"/></th>
  </tr>
</xsl:template>


<xsl:template name="table-cell">
  <xsl:param name="range"/>
  <xsl:param name="h"/>
  <td width="40" align="center">
    <xsl:variable name="x" select="key('id',concat('U',$range,$h),$u)"/>
    <xsl:variable name="c" select=
		  "codepoints-to-string(d:hexfromstring(concat($range,$h))
		   [(. gt 32
		   and
		   . lt 128)
		   or
		   . gt 160]
		   )"/>
    <xsl:choose>
      <xsl:when test="not($x)">
	<xsl:attribute name="class">undescribed</xsl:attribute>
	<xsl:text>&#160;</xsl:text>
      </xsl:when>
      <xsl:when test="$x/description/@unicode='unassigned'">
	<xsl:attribute name="class">unassigned</xsl:attribute>
	<xsl:text>&#160;</xsl:text>
      </xsl:when>
      <xsl:when test="$range='000' and (matches($h,'^[01]') and not($h=('09','0A','0D')))">
	<xsl:attribute name="class">unassigned</xsl:attribute>
	<xsl:text>&#160;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
	<xsl:attribute name="title" select="$x/description"/>
	<xsl:if test="$x/description/@unicode='proposed'">
	  <xsl:attribute name="class">proposed</xsl:attribute>
	  <xsl:message>proposed: <xsl:value-of select="concat($range,$h),$x/description"/></xsl:message>
	</xsl:if>
	<xsl:choose>
	  <xsl:when test="$x/entity[@set=$u/unicode/entitygroups/group[@name='2007']/set/@name]">
	    <a href="bycodes.html#{$x/@id}">
	      <img height="32" width="32" src="{$glyphs}/{$range}/U{$range}{$h}.png"
		   alt="{$x/description}">
		<xsl:if test="$x/@image='none'">
		  <xsl:attribute name="src"><xsl:value-of select="$glyphs"/>/none.png</xsl:attribute>
		</xsl:if>
	      </img>
	    </a>
	  </xsl:when>
	  <xsl:otherwise>
	    <img height="32" width="32" src="{$glyphs}/{$range}/U{$range}{$h}.png"
		 alt="{$x/description}">
	      <xsl:if test="$x/@image='none'">
		<xsl:attribute name="src"><xsl:value-of select="$glyphs"/>/none.png</xsl:attribute>
	      </xsl:if>
	    </img>
	  </xsl:otherwise>
	</xsl:choose>
	<br/>
	<span class="stix">&#160;<xsl:value-of select="$c"/>&#160;</span>
      </xsl:otherwise>
    </xsl:choose>
</td>
</xsl:template>


<!-- -->
<xsl:template name="bycodes">
<xsl:result-document method="html" 
		     encoding="iso-8859-1"
     indent="no"
     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
     doctype-system="http://www.w3.org/TR/html4/loose.dtd"
     href="{$resultbase}bycodes.html">
<html>
<head>
<title>
  Characters Ordered by Unicode
</title>
<xsl:text>&#10;</xsl:text>
  <style type="text/css">.error { color: red }</style>
<xsl:text>&#10;</xsl:text>
<xsl:copy-of select="$css"/>
</head>
<xsl:text>&#10;</xsl:text>
<body>
<h1>Characters Ordered by Unicode</h1>
<xsl:text>&#10;</xsl:text>
<p>
<a href="overview.html">Contents</a><br/>
<a href="byalpha.html">Characters ordered by Entity Name</a><br/>
</p>

<pre>
<xsl:text>&#10;</xsl:text>
<xsl:for-each select="character[entity/@set=/unicode/entitygroups/group[@name='2007']/set/@name]">
<xsl:sort lang="en" select="@id"/>
<a name="{@id}"/>
<xsl:choose>
<xsl:when test="@image='none'">
  <xsl:value-of select="@id"/>
  <xsl:message>missing image: <xsl:value-of select="@id"/></xsl:message>
</xsl:when>
<xsl:otherwise>
<a href="{$glyphs}/{substring(@id,2,3)}/{translate(@id,'x','')}.png">
<xsl:value-of select="@id"/>
</a>
</xsl:otherwise>
</xsl:choose>
<xsl:text>, </xsl:text>
<xsl:value-of select="description"/>
<xsl:value-of select="substring(
'                                      ',
string-length(description))"/>
<xsl:text>, </xsl:text>
<xsl:for-each-group select="entity[@set=/unicode/entitygroups/group[@name='2007']/set/@name]/@id" group-by=".">
<xsl:value-of select="."/>
<xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:for-each-group>
<xsl:text>&#10;</xsl:text>
</xsl:for-each>
</pre>
</body>
</html>
</xsl:result-document>
</xsl:template>

<xsl:template name="byalpha">
  <xsl:result-document method="html" 
		     encoding="iso-8859-1"
		       doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
		       doctype-system="http://www.w3.org/TR/html4/loose.dtd"
		       href="{$resultbase}byalpha.html">
    <html>
      <head>
	<title>Characters Ordered by Entity Name</title>
	<style type="text/css">.error { color: red }</style>
	<xsl:copy-of select="$css"/>
      </head>
      <body>
	<h1>Characters Ordered by Entity Name</h1>
	<p>
	  <a href="overview.html">Contents</a><br/>
	  <a href="bycodes.html">Characters ordered by codes</a><br/>
	</p>
	
	<pre>
	  <xsl:for-each-group
	      select="character/entity[@set=/unicode/entitygroups/group[@name='2007']/set/@name]"
	      group-by="@id">
	    <xsl:sort lang="en" select="@id"/>
	    <xsl:value-of select="@id"/>
	    <xsl:text>, </xsl:text>
	    <xsl:value-of select="substring('                        ',string-length(@id))"/>
	    <xsl:text>, </xsl:text>
	    
	    <xsl:variable name="s" select="string-join(current-group()/replace(@set,'9573-[0-9]*-',''),' ')"/>
	    <xsl:value-of select="$s"/>
	    <xsl:value-of select="substring('                            ',string-length($s))"/>
	    <xsl:text>, </xsl:text>
	    <!-- new bit -->
	    <xsl:choose>
	      <xsl:when test="@image='none'">
		<xsl:value-of select="../@id"/>
		<xsl:message>missing image: <xsl:value-of select="../@id"/></xsl:message>
	      </xsl:when>
	      <xsl:otherwise>
		<a href="{$glyphs}/{substring(../@id,2,3)}/{translate(../@id,'x','')}.png">
		  <xsl:value-of select="../@id"/>
		</a>
	      </xsl:otherwise>
	    </xsl:choose>
	    <!-- end new bit -->
	    <xsl:text> [</xsl:text>
	    <xsl:value-of select="normalize-space(../description)"/>
	    <xsl:text>]</xsl:text>
	    <xsl:text>, </xsl:text>
	    <xsl:value-of select="normalize-space(.)"/>
	    <xsl:text>, </xsl:text>
	    <xsl:text>&#10;</xsl:text>
	  </xsl:for-each-group>
	</pre>
      </body>
    </html>
  </xsl:result-document>
</xsl:template>



<xsl:function name="d:hexfromstring">
<xsl:param name="x"/>
   <xsl:sequence select="(
         d:hex(
           for $i in string-to-codepoints(upper-case($x))
           return if ($i &gt; 64) then $i - 55 else $i - 48))"/>
</xsl:function>

<xsl:function name="d:hex">
<xsl:param name="x"/>
  <xsl:sequence
    select="if (empty($x)) then 0 else ($x[last()] + 16* d:hex($x[position()!=last()]))"/>
</xsl:function>




<xsl:template match="div1[@id='sets']">
  <div id="setsdiv">
    <xsl:apply-templates select="*"/>
    <ul>
    <xsl:for-each select="$u/unicode/entitygroups/group[@name='2007']/set">
	<li><a href="{replace(@name,'^[0-9][0-9---]*','')}.html">
	  <xsl:apply-templates select="." mode="name"/>
	</a>
	<xsl:text>&#160;&#160;</xsl:text>
	<xsl:value-of select="replace(@fpi,'.*ENTITIES ([^/]*)//.*','$1')"/></li>
    </xsl:for-each>
    </ul>
</div>
</xsl:template>

<!--
<xsl:template match="div1[@id='blocks']">
<div id="sets">
  <dl>
  <xsl:apply-templates select="*"/>
  <xsl:for-each-group select="$blocks[substring(@start,1,3)=$blockstarts]" group-by="substring(@start,1,3)">
    <xsl:for-each select="current-group()">
      <dt><xsl:value-of select="@name"/></dt>
    </xsl:for-each>
    <dd><a href="../2007doc/{current-grouping-key()}.html"><xsl:value-of select="current-grouping-key()"/></a></dd>
  </xsl:for-each-group>
  </dl>
</div>
</xsl:template>
-->

<xsl:template match="div1[@id='blocks']">
  <div id="blocksdiv">
    <xsl:apply-templates select="*"/>
    <table>
      <xsl:for-each-group select="$blocks[substring(@start,1,3)=$blockstarts]" group-by="substring(@start,1,3)">
	<xsl:variable  name="s" select="d:hexfromstring(substring(@start,1,3))"/>
	<xsl:variable name="e" select="d:hexfromstring(substring(@end,1,3))"/>
	
	<xsl:for-each select="$s to $e">
	  <xsl:variable name="p" select="string-join(for $x in (. idiv 256, (. mod 256) idiv 16, . mod 16)
					 return $hex[$x+1],'')"/>
	  <tr>
	    <td>
	      <xsl:value-of select="$p"/>
	    </td>
	    <td>
	      <a href="{$p}.html">
		<xsl:value-of select="current-group()/@name" separator=", "/>
		<xsl:if test="position()!=1"> (continued)</xsl:if>
	      </a>
	    </td>
	  </tr>
	</xsl:for-each>
      </xsl:for-each-group>
    </table>
  </div>
</xsl:template>

<xsl:template match="graphic[@role='glyph']">
 <img height="32" width="32"  style="position: relative; top: 10px;" 
       src="{$glyphs}/{substring(@source,2,3)}/{@source}.png"
       alt="{key('id',@source,$u)/description}">
  </img>
</xsl:template>

</xsl:stylesheet>
