<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:variable name="color">
    <color type="public" value="green"/>
    <color type="package" value="blue"/>
    <color type="protected" value="fuchsia"/>
    <color type="private" value="red"/>
  </xsl:variable>

  <xsl:variable name="accesscolor"
    select="document('')/*/xsl:variable[@name='color']"/>
  
  <xsl:template match="refset">
    <html>
      <head>
        <title>Access</title>
        <style>
h1 {
  font-size: 12pt;
  margin-bottom:2pt;
}
p {
  margin-top:0;
  margin-bottom:0;
  margin-left:12pt;
}
        </style>
      </head>
      <body>
        <xsl:apply-templates select="class">
          <xsl:sort select="name"/>
        </xsl:apply-templates>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="class">
    <h1><xsl:value-of select="name"/></h1>
    <xsl:apply-templates select="field">
      <xsl:sort select="name"/>
    </xsl:apply-templates>
    <xsl:apply-templates select="method">
      <xsl:sort select="name"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="field|method">
    <xsl:variable name="bgcolor">
      <xsl:choose>
        <xsl:when test="not(accesscount/*)">silver</xsl:when>
        <xsl:when test="access='public' and accesscount/* and not(accesscount/public)">yellow</xsl:when>
        <xsl:when test="access='package'">aqua</xsl:when>
        <xsl:when test="access='protected' and accesscount/* and not(accesscount/protected)">yellow</xsl:when>
        <xsl:otherwise>white</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <p>
      <span style="background-color:{$bgcolor};color:{$accesscolor/color[@type=current()/access]/@value};">
        <xsl:value-of select="name"/>
      </span>
      <xsl:text>: </xsl:text>
      <xsl:apply-templates select="accesscount/*"/>
    </p>
  </xsl:template>

  <xsl:template match="public|private|package|protected">
    <span style="color:{$accesscolor/color[@type=name(current())]/@value};">
      <xsl:value-of select="."/>
    </span>
    <xsl:text> </xsl:text>
  </xsl:template>

</xsl:stylesheet>