<!-- 
p2p2html.xsl - display p3p document as html with links to the specification.
Description and revision history at http://www.w3.org/2003/07/p3p2html/
$Id: p3p2html.xsl,v 1.6 2003/07/21 17:47:06 eric Exp $
-->
<xsl:transform version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns="http://www.w3.org/1999/xhtml"
 xmlns:p3p="http://www.w3.org/2002/01/P3Pv1"
 exclude-result-prefixes="p3p"
>

  <!-- re-use Evan Lenz's xml-to-string from http://www.xmlportfolio.com/xml-to-string -->
  <xsl:import href="xml-to-string.xsl"/>
  <!-- overloaded global parameters -->
  <xsl:param name="attribute-delimiter" select="'\&quot;'"/>
  <!-- overloaded templates from xml-to-string -->
  <xsl:template match="/" name="xml-to-string-root-rule">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="comment()" mode="xml-to-string">
    <span class="comment">
      <xsl:value-of select="$comment-start"/>
      <xsl:call-template name="comment-text">
        <xsl:with-param name="text" select="string(.)"/>
      </xsl:call-template>
      <xsl:value-of select="$comment-end"/>
    </span>
  </xsl:template>
  <!-- end xml-to-string -->

  <xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>

  <xsl:param name="baseURI"/>

  <!-- MAIN -->
  <xsl:template match="/">
    <html xml:lang="en" lang="en">
      <head>
        <title>p3p reviewer</title>
        <style type='text/css'>
          pre.unknownElement {        background:#ffbfbf;       font-family:'courier new',courier,serif;   }
          pre.unknownAttribute {        background:#ffbfbf;       font-family:'courier new',courier,serif;   }
          span.comment {        color:#ff0000;       font-family:'courier new',courier,serif;   }
          div {		text-indent: 4em	}
          dd.redFlag {	color:#ff0000;background:#200000	}
        </style>
      </head>
      <body>
        <h1>P3P viewer</h1>
        <p>processed with <a href="p3p2html.xsl">p3p2html.xsl</a>.</p>

        <dl>
          <xsl:for-each select="@*">
            <xsl:choose>
              <xsl:when test="self::xml:lang"/>
              <xsl:otherwise>
                <xsl:apply-templates select="." mode="unknownAttr">
                  <xsl:with-param name="name" select="name(..)"/>
                </xsl:apply-templates>
              </xsl:otherwise>
            </xsl:choose>      
          </xsl:for-each>
          <xsl:for-each select="*|text()">
            <xsl:choose>
              <xsl:when test="self::p3p:POLICIES">
                <xsl:text>&#xA;</xsl:text>
                <xsl:apply-templates select="."/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:apply-templates select="." mode="unknownElement"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:for-each>
        </dl>
        <p>
          <a href="http://validator.w3.org/check/referer">
            <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88"/>
          </a>
        </p>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="p3p:POLICIES">
    <dt><a href="http://www.w3.org/TR/P3P/#POLICIES">POLICIES</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:choose>
            <xsl:when test="self::xml:lang"/>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownAttr">
                <xsl:with-param name="name" select="name(..)"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:EXPIRY">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:DATASCHEMA">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:POLICY">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:EXPIRY">
    <dt><a href="http://www.w3.org/TR/P3P/#EXPIRY">EXPIRY</a>:</dt>
    <dd><dl>
      <xsl:for-each select="@*">
        <xsl:choose>
          <xsl:when test="self::date">
            <xsl:apply-templates select="." mode="dtpair">
              <xsl:with-param name="label" select="'date'"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:when test="self::max-age">
            <xsl:apply-templates select="." mode="dtpair">
              <xsl:with-param name="label" select="'max-age'"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="." mode="unknownAttr">
              <xsl:with-param name="name" select="name(..)"/>
            </xsl:apply-templates>
          </xsl:otherwise>
        </xsl:choose>      
      </xsl:for-each>

    <xsl:text>&#xA;</xsl:text>
    <xsl:for-each select="*|text()">
      <xsl:apply-templates select="*" mode="unknownElement"/>
    </xsl:for-each>
    </dl></dd>
  </xsl:template><!-- p3p:EXPIRY -->

  <!-- !!! missing dataschema -->

  <xsl:template match="p3p:POLICY">
    <dt><a href="http://www.w3.org/TR/P3P/#POLICY">POLICY</a>:</dt>
    <dd>
      <dl>
        <xsl:choose>
          <xsl:when test="p3p:TEST">
            <dt>Test policy, not in effect!</dt>
          </xsl:when>
        </xsl:choose>
        <xsl:for-each select="@*">
          <xsl:choose>
            <xsl:when test="self::name">
              <xsl:apply-templates select="." mode="dtpair">
                <xsl:with-param name="label" select="'policy name'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::discuri">
              <xsl:apply-templates select="." mode="dthref">
                <xsl:with-param name="label" select="'natural language privacy statement'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::xml:lang"/>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownAttr">
                <xsl:with-param name="name" select="name(..)"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:ENTITY">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="p3p:TEST"/>
            <xsl:when test="self::p3p:ACCESS">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:DISPUTES-GROUP">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:STATEMENT">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template><!-- /p3p:POLICY -->

  <xsl:template match="p3p:ENTITY">
    <dt><a href="http://www.w3.org/TR/P3P/#ENTITY">ENTITY</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:DATA-GROUP">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:DATA-GROUP">
    <dt><a href="http://www.w3.org/TR/P3P/#ENTITY">DATA-GROUP</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:DATA">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:DATA">
    <!-- dt><a href="http://www.w3.org/TR/P3P/#ENTITY">DATA</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl-->
        <xsl:for-each select="@*">
          <xsl:choose>
            <xsl:when test="self::ref">
              <dt><a href="http://www.w3.org/TR/P3P/#Business-Data">
              <xsl:value-of select="."/></a></dt>
              <dd><xsl:value-of select="../text()"/></dd>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownAttr">
                <xsl:with-param name="name" select="name(..)"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
        <xsl:for-each select="*">
          <xsl:choose>
            <xsl:when test="self::p3p:CATEGORIES">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      <!-- /dl>
    </dd -->
  </xsl:template>

  <xsl:template match="p3p:ACCESS">
    <dt><a href="http://www.w3.org/TR/P3P/#ACCESS">ACCESS</a>:</dt>
    <dd>
      <dl>
        <xsl:text>&#xA;</xsl:text>
        <xsl:for-each select="@*">
          <xsl:with-param name="name" select="name(..)"/>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:nonident">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>Identified Data is Not Used</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:all">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>All Identifiable Information</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:contact-and-other">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>Identified Contact Information and Other Identified Data</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:ident-contact">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>Identifiable Contact Information</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:other-ident">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>Other Identified Data</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:none">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>None</xsl:text></dd>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:DISPUTES-GROUP">
    <dt><a href="http://www.w3.org/TR/P3P/#DISPUTES">DISPUTES-GROUP</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:DISPUTES">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:DISPUTES">
    <dt><a href="http://www.w3.org/TR/P3P/#DISPUTES">DISPUTES</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:choose>
            <xsl:when test="self::resolution-type">
              <xsl:apply-templates select="." mode="dtpair">
                <xsl:with-param name="label" select="'resolution type'"/>
                <xsl:with-param name="class" select="'redFlag'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::service">
              <xsl:apply-templates select="." mode="dthref">
                <xsl:with-param name="label" select="'information about the relevant court or applicable law'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::verification">
              <xsl:apply-templates select="." mode="dtpair">
                <xsl:with-param name="label" select="'URI or certificate that can be used for verification purposes'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::short-description">
              <xsl:apply-templates select="." mode="dtpair">
                <xsl:with-param name="label" select="'human readable description of the forum, applicable law, or third party organization; or customer contact information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownAttr">
                <xsl:with-param name="name" select="name(..)"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:LONG-DESCRIPTION">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:IMG">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:REMEDIES">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:LONG-DESCRIPTION">
    <xsl:for-each select="@*">
      <xsl:apply-templates select="." mode="unknownAttr">
        <xsl:with-param name="name" select="name(..)"/>
      </xsl:apply-templates>
    </xsl:for-each>
    <xsl:for-each select="*">
      <xsl:apply-templates select="." mode="unknownElement"/>
    </xsl:for-each>
    <xsl:text>&#xA;</xsl:text>
    <dt>human readable description</dt>
    <dd><xsl:value-of select="text()"/></dd>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

  <xsl:template match="p3p:IMG">
    <dt><a href="http://www.w3.org/TR/P3P/#IMG">IMG</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <img>
        <xsl:for-each select="@*">
          <xsl:choose>
            <xsl:when test="self::src">
              <xsl:attribute name="src">
                <xsl:value-of select="."/>
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="self::width">
              <xsl:attribute name="width">
                <xsl:value-of select="."/>
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="self::height">
              <xsl:attribute name="height">
                <xsl:value-of select="."/>
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="self::alt">
              <xsl:attribute name="alt">
                <xsl:value-of select="."/>
              </xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownAttr">
                <xsl:with-param name="name" select="name(..)"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:apply-templates select="." mode="unknownElement"/>
        </xsl:for-each>
      </img>
    </dd>
  </xsl:template><!-- p3p:IMG -->

  <xsl:template match="p3p:REMEDIES">
    <dt><a href="http://www.w3.org/TR/P3P/#REMEDIES">REMEDIES</a>:</dt>
    <dd>
      <dl>
        <xsl:text>&#xA;</xsl:text>
        <xsl:for-each select="@*">
          <xsl:with-param name="name" select="name(..)"/>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:correct">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>Errors or wrongful actions arising in connection with the privacy policy will be remedied by the service.</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:money">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>If the service provider violates its privacy policy it will pay the individual an amount specified in the human readable privacy policy or the amount of damages.</xsl:text></dd>
            </xsl:when>
            <xsl:when test="self::p3p:law">
              <xsl:text>&#xA;</xsl:text>
              <dd><xsl:text>Remedies for breaches of the policy statement will be determined based on the law referenced in the human readable description.</xsl:text></dd>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:STATEMENT">
    <dt><a href="http://www.w3.org/TR/P3P/#STATEMENT">STATEMENT</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:CONSEQUENCE">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:PURPOSE">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:RECIPIENT">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:RETENTION">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:DATA-GROUP">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:when test="self::p3p:NON-IDENTIFIABLE">
              <xsl:text>&#xA;either no data is collected (including Web logs), or that the organization collecting the data will anonymize the data referenced in the enclosing STATEMENT.</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:CONSEQUENCE">
    <xsl:for-each select="@*">
      <xsl:apply-templates select="." mode="unknownAttr">
        <xsl:with-param name="name" select="name(..)"/>
      </xsl:apply-templates>
    </xsl:for-each>
    <xsl:for-each select="*">
      <xsl:apply-templates select="." mode="unknownElement"/>
    </xsl:for-each>
    <xsl:text>&#xA;</xsl:text>
    <dt><a href="http://www.w3.org/TR/P3P/#CONSEQUENCE">why the suggested practice may be valuable</a></dt>
    <dd><xsl:value-of select="text()"/></dd>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

  <xsl:template match="p3p:PURPOSE">
    <dt><a href="http://www.w3.org/TR/P3P/#PURPOSE">PURPOSE</a>:</dt>
    <xsl:text>&#xA;</xsl:text>
    <dd>
      <dl>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:current">
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Completion and Support of Activity For Which Data Was Provided'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:admin">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Web Site and System Administration'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:develop">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Research and Development'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:tailoring">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'One-time Tailoring'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:pseudo-analysis">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Pseudonymous Analysis'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:pseudo-decision">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Pseudonymous Decision'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:individual-analysis">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Individual Analysis'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:individual-decision">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Individual Decision'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:contact">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Contacting Visitors for Marketing of Services or Products'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:historical">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Historical Preservation'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:telemarketing">
              <xsl:apply-templates select="." mode="requiredOpt">
                <xsl:with-param name="desc" select="'Telephone Marketing'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:other-purpose">
              <xsl:apply-templates select="." mode="dataElement">
                <xsl:with-param name="desc" select="'Other Uses'"/>
                <xsl:with-param name="class" select="'redFlag'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template>

  <xsl:template match="p3p:RECIPIENT">
    <dt><a href="http://www.w3.org/TR/P3P/#RECIPIENT">RECIPIENT</a>:</dt>
    <dd>
      <dl>
        <xsl:text>&#xA;</xsl:text>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:ours">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'only ourselves and our agents'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:same">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="requiredOptDataElement">
                <xsl:with-param name="desc" select="'legal entities following our practices'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:other-recipient">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="requiredOptDataElement">
                <xsl:with-param name="desc" select="'legal entities following different practices'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:delivery">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="requiredOptDataElement">
                <xsl:with-param name="desc" select="'delivery services following different practices'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:public">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="requiredOptDataElement">
                <xsl:with-param name="desc" select="'public fora'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:unlrelated">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="requiredOptDataElement">
                <xsl:with-param name="desc" select="'unrelated third parties'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template><!-- /p3p:RECIPIENT -->

  <xsl:template match="p3p:RETENTION">
    <dt><a href="http://www.w3.org/TR/P3P/#RETENTION">RETENTION</a>:</dt>
    <dd>
      <dl>
        <xsl:text>&#xA;</xsl:text>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:no-retention">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'not retained'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:stated-purpose">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'for the stated purpose'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:legal-requirement">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'stated purpose by law'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:indefinitely">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'indeterminate period of time'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:business-practices">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'by business practices'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template><!-- /p3p:RETENTION -->

  <xsl:template match="p3p:CATEGORIES">
    <dt><a href="http://www.w3.org/TR/P3P/#CATEGORIES">CATEGORIES</a>:</dt>
    <dd>
      <dl>
        <xsl:text>&#xA;</xsl:text>
        <xsl:for-each select="@*">
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:physical">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Physical Contact Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:online">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Online Contact Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:uniqueid">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Unique Identifiers'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:purchase">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Purchase Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:financial">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Financial Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:computer">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Computer Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:navigation">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Navigation and Click-stream Data'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:interactive">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Interactive Data'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:demographic">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Demographic and Socioeconomic Data'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:content">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Content'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:state">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'State Management Mechanisms'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:political">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Political Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:health">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Health Information'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:preference">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Preference Data'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:location">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="bareElement">
                <xsl:with-param name="desc" select="'Location Data'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="self::p3p:government">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="." mode="dataElement">
                <xsl:with-param name="desc" select="'Government-issued Identifiers'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template><!-- /p3p:CATEGORIES -->

  <!-- FACTORED PRODUCTIONS -->

  <xsl:template match="*" mode="bareElement">
      <xsl:param name="desc"/>
    <xsl:for-each select="@*">
      <xsl:apply-templates select="." mode="unknownAttr">
        <xsl:with-param name="name" select="name(..)"/>
      </xsl:apply-templates>
    </xsl:for-each>
    <xsl:for-each select="*|text()">
      <xsl:apply-templates select="." mode="unknownElement"/>
    </xsl:for-each>
    <dt><xsl:value-of select="name(.)"/></dt>
    <dd><xsl:value-of select="$desc"/></dd>
  </xsl:template>

  <xsl:template match="*" mode="dataElement">
    <xsl:param name="desc"/>
    <xsl:param name="class"/>
    <xsl:for-each select="@*">
      <xsl:apply-templates select="." mode="unknownAttr">
        <xsl:with-param name="name" select="name(..)"/>
      </xsl:apply-templates>
    </xsl:for-each>
    <xsl:for-each select="*">
      <xsl:apply-templates select="." mode="unknownElement"/>
    </xsl:for-each>
    <!-- dt><xsl:value-of select="name(.)"/></dt -->
    <dt><xsl:value-of select="$desc"/></dt>
    <dd>
      <xsl:if test="$class">
        <xsl:attribute name="class">
          <xsl:value-of select="$class"/>
        </xsl:attribute>        
      </xsl:if>
      <xsl:value-of select="text()"/>
    </dd>
  </xsl:template>

  <xsl:template match="*" mode="requiredOpt">
    <xsl:param name="desc"/>
    <xsl:for-each select="@*">
      <xsl:choose>
        <xsl:when test="self::p3p:required">
          <xsl:apply-templates select="." mode="dtpair">
            <xsl:with-param name="label" select="$desc"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>      
    </xsl:for-each>
    <xsl:for-each select="*|text()">
      <xsl:apply-templates select="." mode="unknownElement"/>
    </xsl:for-each>
    <dt><xsl:value-of select="name(.)"/></dt>
    <dd><xsl:value-of select="$desc"/></dd>
  </xsl:template>

  <xsl:template match="*" mode="requiredOptDataElement">
    <xsl:param name="desc"/>
    <xsl:for-each select="@*">
      <xsl:choose>
        <xsl:when test="self::p3p:required">
          <xsl:apply-templates select="." mode="dtpair">
            <xsl:with-param name="label" select="$desc"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="." mode="unknownAttr">
            <xsl:with-param name="name" select="name(..)"/>
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>      
    </xsl:for-each>
    <xsl:for-each select="*">
      <xsl:apply-templates select="." mode="unknownElement"/>
    </xsl:for-each>
    <dt><xsl:value-of select="name(.)"/></dt>
    <dd><xsl:value-of select="$desc"/></dd>
    <dd><xsl:value-of select="text()"/></dd>
  </xsl:template>

  <!-- LIBRARY -->

  <xsl:template match="@*" mode="dtpair">
    <xsl:param name="label"/>
    <xsl:param name="class"/>
    <dt><xsl:value-of select="$label"/><xsl:text>:</xsl:text></dt>
    <dd>
      <xsl:if test="$class">
        <xsl:attribute name="class">
          <xsl:value-of select="$class"/>
        </xsl:attribute>        
      </xsl:if>
      <xsl:value-of select="."/>
    </dd>
  </xsl:template>

  <xsl:template match="@*" mode="dthref">
    <xsl:param name="label"/>
    <dt><a href="">
    <xsl:attribute name="href">
      <xsl:value-of select="."/>
    </xsl:attribute>
    <xsl:value-of select="$label"/><xsl:text>:</xsl:text></a></dt>
  </xsl:template>

  <!-- Show unparsed data to the user as it may have consequences he/she
       would otherwise be unaware of. -->

  <xsl:template match="*">
    <xsl:text>&#xA;</xsl:text>
    <dt>uncaught element:</dt>
    <dd>
      <pre class="uncaught">
        <xsl:call-template name="xml-to-string"/>
      </pre>
    </dd>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

  <xsl:template match="@*" mode="unknownAttr">
    <xsl:param name="name"/>
    <xsl:text>&#xA;</xsl:text>
    <dt>unknown attribute in P3P policy element <xsl:value-of select="$name"/>:</dt>
    <dd>
      <pre class="unknownAttribute">
        <xsl:call-template name="xml-to-string"/>
      </pre>
    </dd>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

  <xsl:template match="*" mode="unknownElement">
    <xsl:text>&#xA;</xsl:text>
    <dt>unknown element in P3P policy:</dt>
    <dd>
      <pre class="unknownElement">
        <xsl:call-template name="xml-to-string"/>
      </pre>
    </dd>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

  <!-- TEMPLATE -->

  <xsl:template match="p3p:PROD1">
    <dt><a href="http://www.w3.org/TR/P3P/#PROD1">PROD1</a>:</dt>
    <dd>
      <dl>
        <xsl:text>&#xA;</xsl:text>
        <xsl:for-each select="@*">
          <xsl:choose>
            <xsl:when test="self::attr1">
              <xsl:apply-templates select="." mode="dtpair">
                <xsl:with-param name="label" select="'attr1 label'"/>
              </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownAttr">
                <xsl:with-param name="name" select="name(..)"/>
              </xsl:apply-templates>
            </xsl:otherwise>
          </xsl:choose>      
        </xsl:for-each>
        <xsl:for-each select="*|text()">
          <xsl:choose>
            <xsl:when test="self::p3p:elem1">
              <xsl:text>&#xA;</xsl:text>
              <xsl:apply-templates select="."/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="." mode="unknownElement"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </dl>
    </dd>
  </xsl:template><!-- /p3p:PROD1 -->

</xsl:transform>
