<?xml version='1.0'?>
<!--* <!DOCTYPE xsl:stylesheet PUBLIC 'http://www.w3.org/1999/XSL/Transform'
      '/SGML/Public/W3C/xslt10.dtd' > *-->
<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:p='http://www.w3.org/2001/05/PSVInfosetExtension'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:i='http://www.w3.org/2001/05/XMLInfoset' 
>

<!--* A stylesheet which provides a quickly hacked display of XSV 
    * psvi output in alternating form.
    *-->

 <xsl:strip-space elements="i:document i:children i:element i:character i:attributes i:namespaceAttributes i:inScopeNamespaces i:namespace p:validationContext p:typeDefinition p:declaration"/>

 <xsl:variable name="ascii">.........&#10;..&#13;..................&#32;&#33;&#34;&#35;&#36;&#37;&#38;&#39;&#40;&#41;&#42;&#43;&#44;&#45;&#46;&#47;&#48;&#49;&#50;&#51;&#52;&#53;&#54;&#55;&#56;&#57;&#58;&#59;&#60;&#61;&#62;&#63;&#64;&#65;&#66;&#67;&#68;&#69;&#70;&#71;&#72;&#73;&#74;&#75;&#76;&#77;&#78;&#79;&#80;&#81;&#82;&#83;&#84;&#85;&#86;&#87;&#88;&#89;&#90;&#91;&#92;&#93;&#94;&#95;&#96;&#97;&#98;&#99;&#100;&#101;&#102;&#103;&#104;&#105;&#106;&#107;&#108;&#109;&#110;&#111;&#112;&#113;&#114;&#115;&#116;&#117;&#118;&#119;&#120;&#121;&#122;&#123;&#124;&#125;&#126;&#127;</xsl:variable>
 <xsl:variable name="vafull">white</xsl:variable>
 <xsl:variable name="vapart">#AAC</xsl:variable>
 <xsl:variable name="vanone">#888</xsl:variable>
 <xsl:variable name="vaother">#644</xsl:variable>

 <xsl:variable name="vvalid">green</xsl:variable>
 <xsl:variable name="vinvalid">red</xsl:variable>
 <xsl:variable name="vunknown">orange</xsl:variable><!--* was blue *-->
 <xsl:variable name="vother">#F88</xsl:variable>

 <xsl:template match='*'>
  <xsl:element name="br"/>
  <xsl:element name="span">
   <xsl:attribute name="style">color:red</xsl:attribute>
   <xsl:attribute name='title'><xsl:value-of select="name()"/></xsl:attribute>
   <xsl:text>&lt;&lt;</xsl:text>
   <xsl:value-of select="name()"/>
   <xsl:text>&gt;&gt;</xsl:text>
   <xsl:apply-templates/>
   <xsl:text>&lt;&lt;/</xsl:text>
   <xsl:value-of select="name()"/>
   <xsl:text>&gt;&gt;</xsl:text>
  </xsl:element>
  <xsl:element name="br"/>
 </xsl:template>

 <xsl:template match='comment()'>
  <xsl:comment>
   <xsl:value-of select="."/>
  </xsl:comment>
 </xsl:template>
 
 <xsl:template match='processing-instruction()'>
  <xsl:variable name="pitarget" select="name()"/>
  <xsl:processing-instruction name="{$pitarget}">
   <xsl:value-of select="."/>
  </xsl:processing-instruction>
 </xsl:template>

 <xsl:template match="/">
  <xsl:text>&#xA;</xsl:text>
  <xsl:element name="html">
   <xsl:element name="head">
    <xsl:element name="title">PSVI display</xsl:element>
    <xsl:text>&#xA;</xsl:text>
   </xsl:element>
   <xsl:text>&#xA;</xsl:text>
   <xsl:element name="body">
    <xsl:call-template name="write-legend"/>
    <xsl:apply-templates/>
   </xsl:element>
   <xsl:text>&#xA;</xsl:text>
  </xsl:element>
  <xsl:text>&#xA;</xsl:text>
 </xsl:template>

 <xsl:template match="i:document">
  <xsl:apply-templates select="i:children"/>
 </xsl:template>
 <xsl:template match="i:document/i:children">
  <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="i:inScopeNamespaces"/>
 <xsl:template match="i:baseURI"/>
 <xsl:template match="i:validationContext"/>

 <xsl:template match="i:element">
  <xsl:element name="div">
   <xsl:attribute name="style">
    <xsl:text>margin-left: 1em;</xsl:text>
    <xsl:call-template name="color-coding"/>
   </xsl:attribute>
   <xsl:element name="span">
    <xsl:attribute name="style">font-weight:bold</xsl:attribute>
    <xsl:attribute name='title'>
     <xsl:call-template name="showname"/>
     <xsl:if test="p:schemaErrorCode">
      <xsl:text> [</xsl:text>
      <xsl:value-of select="p:schemaErrorCode"/>
      <xsl:text>]</xsl:text>
     </xsl:if>
    </xsl:attribute>
    <xsl:text>&lt;</xsl:text>
    <xsl:call-template name="showname"/>
    <xsl:apply-templates select="i:attributes"/>
    <xsl:text>&gt;</xsl:text>
   </xsl:element>
   <xsl:choose>
    <xsl:when test="count(i:children/*) > 0">
     <xsl:apply-templates select="i:children"/>
    </xsl:when>
    <xsl:when test="count(i:children/*) = 0 and count(i:element) > 0">
     <!--* this case appears to be caused by a bug in Xerces,
     which sometimes (unsure when) spits out a series of elements
     followed by an empty children element.
     ~/2003/schema/exx/Whitehead/testdoc exercises this bug.
     *-->
     <xsl:apply-templates select="i:element"/>
    </xsl:when>
    <xsl:when test="p:schemaNormalizedValue">
     <xsl:value-of select="p:schemaNormalizedValue"/>
    </xsl:when>
    <xsl:otherwise></xsl:otherwise>
   </xsl:choose>
   <xsl:element name="span">
    <xsl:attribute name="style">font-weight:bold</xsl:attribute>
    <xsl:text>&lt;/</xsl:text>
    <xsl:call-template name="showname"/>
    <xsl:text>&gt;</xsl:text>
   </xsl:element>
  </xsl:element>
 </xsl:template>

 <xsl:template name="showname">
  <xsl:if test="i:namespaceName[not(@xsi:nil='true')]">
   <xsl:choose>
    <xsl:when test="i:prefix[not(@xsi:nil='true')]">
     <xsl:value-of select="i:prefix"/>
     <xsl:text>:</xsl:text>
    </xsl:when>
    <xsl:otherwise>
     <xsl:text>{</xsl:text>
     <xsl:value-of select="i:namespaceName"/>
     <xsl:text>}</xsl:text>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
  <xsl:value-of select="./i:localName"/>
 </xsl:template>

 <xsl:template match="i:attributes">
   <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="i:attribute">
  <xsl:text>&#160;</xsl:text>
  <xsl:element name="span">
   <xsl:call-template name="style-with-color"/>
   <xsl:attribute name='title'>
    <xsl:call-template name="showname"/>
    <xsl:if test="p:schemaErrorCode[not(@xsi:nil='true')]">
     <xsl:text> [</xsl:text>
     <xsl:value-of select="p:schemaErrorCode"/>
     <xsl:text>]</xsl:text>
    </xsl:if>
   </xsl:attribute>
   <xsl:call-template name="showname"/>
   <xsl:text>="</xsl:text>
   <xsl:value-of select="i:normalizedValue"/>
   <xsl:text>"</xsl:text>
  </xsl:element>
 </xsl:template>
 <xsl:template match="i:element/i:children">
  <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="i:character/i:textContent">
  <xsl:value-of select="."/>
 </xsl:template>

 <xsl:template match="i:character/i:characterCode">
  <xsl:value-of select="substring($ascii,number(.),1)"/>
 </xsl:template>
 <xsl:template match="i:children/i:character">
  <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="i:character/i:elementContentWhitespace"/>
 <xsl:template match="p:pattern/p:value"/>

 <xsl:template match="i:docTypeDeclaration"/>
 <xsl:template match="i:comment">
  <xsl:element name="div">
   <xsl:attribute name="style">
    <xsl:text>margin-left: 1em; color: black;</xsl:text>
   </xsl:attribute>
   <xsl:text>&lt;!--</xsl:text>
   <xsl:element name="span">
    <xsl:attribute name="style">color: gray</xsl:attribute>
    <xsl:value-of select="./i:content"/>
   </xsl:element>
   <xsl:text>--&gt;</xsl:text>
  </xsl:element>
 </xsl:template>

 <xsl:template name="write-legend">
  <xsl:element name="h3">PSVI output</xsl:element>
  <xsl:element name="p">
   <xsl:text>Display colors:</xsl:text>
  </xsl:element>
  <xsl:call-template name="makelegend"/>
 </xsl:template>

 <xsl:template name="makelegend">
  <xsl:element name="ul">
   <xsl:call-template name="triple-entry">
    <xsl:with-param name="kw">full</xsl:with-param>
    <xsl:with-param name="bg" select="$vafull"/>
   </xsl:call-template>
   <xsl:call-template name="triple-entry">
    <xsl:with-param name="kw">partial</xsl:with-param>
    <xsl:with-param name="bg" select="$vapart"/>
   </xsl:call-template>
   <xsl:call-template name="triple-entry">
    <xsl:with-param name="kw">none</xsl:with-param>
    <xsl:with-param name="bg" select="$vanone"/>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">absent</xsl:with-param>
    <xsl:with-param name="valid">absent</xsl:with-param>
   </xsl:call-template>
  </xsl:element>
 </xsl:template>
 <xsl:template name="triple-entry">
  <xsl:param name="kw">other</xsl:param>
  <xsl:param name="bg">#EBE</xsl:param>
  <xsl:element name="li">
   <xsl:attribute name="style">
    <xsl:text>background-color: </xsl:text>
    <xsl:value-of select="$bg"/>
   </xsl:attribute>
   <xsl:text>[validation-attempted] = </xsl:text>
   <xsl:value-of select="$kw"/>
   <xsl:text>, [validity] = </xsl:text>
   <xsl:call-template name="write-validity-codes"/>
  </xsl:element>
 </xsl:template>
 <xsl:template name="write-validity-codes">
  <xsl:element name="span">
   <xsl:attribute name="style">
    <xsl:text>color: </xsl:text>
    <xsl:value-of select="$vvalid"/>
   </xsl:attribute>
   <xsl:text>valid</xsl:text>
  </xsl:element>
  <xsl:text>, or </xsl:text>
  <xsl:element name="span">
   <xsl:attribute name="style">
    <xsl:text>color: </xsl:text>
    <xsl:value-of select="$vinvalid"/>
   </xsl:attribute>
   <xsl:text>invalid</xsl:text>
  </xsl:element>
  <xsl:text>, or </xsl:text>
  <xsl:element name="span">
   <xsl:attribute name="style">
    <xsl:text>color: </xsl:text>
    <xsl:value-of select="$vunknown"/>
   </xsl:attribute>
   <xsl:text>notKnown</xsl:text>
  </xsl:element>
 </xsl:template>

 <xsl:template name="makelegend-old">
  <xsl:element name="ul">
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">full</xsl:with-param>
    <xsl:with-param name="valid">valid</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">full</xsl:with-param>
    <xsl:with-param name="valid">invalid</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">full</xsl:with-param>
    <xsl:with-param name="valid">notKnown</xsl:with-param>
    <xsl:with-param name="note">(should not occur)</xsl:with-param>
   </xsl:call-template>

   <xsl:call-template name="entry">
    <xsl:with-param name="tried">partial</xsl:with-param>
    <xsl:with-param name="valid">valid</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">partial</xsl:with-param>
    <xsl:with-param name="valid">invalid</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">partial</xsl:with-param>
    <xsl:with-param name="valid">notKnown</xsl:with-param>
   </xsl:call-template>

   <xsl:call-template name="entry">
    <xsl:with-param name="tried">none</xsl:with-param>
    <xsl:with-param name="valid">valid</xsl:with-param>
    <xsl:with-param name="note">(should not occur)</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">none</xsl:with-param>
    <xsl:with-param name="valid">invalid</xsl:with-param>
    <xsl:with-param name="note">(should not occur)</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">none</xsl:with-param>
    <xsl:with-param name="valid">notKnown</xsl:with-param>
   </xsl:call-template>
   <xsl:call-template name="entry">
    <xsl:with-param name="tried">absent</xsl:with-param>
    <xsl:with-param name="valid">absent</xsl:with-param>
   </xsl:call-template>
  </xsl:element>
 </xsl:template>

 <xsl:template name="entry">
  <xsl:param name="tried">other</xsl:param>
  <xsl:param name="valid">other</xsl:param>
  <xsl:variable name="fg">
   <xsl:choose>
    <xsl:when test="$valid='valid'"><xsl:value-of select="$vvalid"/></xsl:when>
    <xsl:when test="$valid='invalid'"><xsl:value-of select="$vinvalid"/></xsl:when>
    <xsl:when test="$valid='notKnown'"><xsl:value-of select="$vunknown"/></xsl:when>
    <xsl:otherwise><xsl:value-of select="$vother"/></xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="bg">
   <xsl:choose>
    <xsl:when test="$tried='full'"><xsl:value-of select="$vafull"/></xsl:when>
    <xsl:when test="$tried='partial'"><xsl:value-of select="$vapart"/></xsl:when>
    <xsl:when test="$tried='none'"><xsl:value-of select="$vanone"/></xsl:when>
    <xsl:otherwise><xsl:value-of select="$vaother"/></xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:element name="li">
   <xsl:attribute name="style">
    <xsl:text>color: </xsl:text>
    <xsl:value-of select="$fg"/>
    <xsl:text>; background-color: </xsl:text>
    <xsl:value-of select="$bg"/>
    <xsl:text>;</xsl:text>
   </xsl:attribute>
   <xsl:text>[validation attempted] = </xsl:text>
   <xsl:value-of select="$tried"/>
   <xsl:text>, [validity] = </xsl:text>
   <xsl:value-of select="$valid"/>
  </xsl:element>
 </xsl:template>

 <xsl:template name="style-with-color">
  <xsl:attribute name="style">
   <xsl:call-template name="color-coding"/>
  </xsl:attribute>
 </xsl:template>
 <xsl:template name="color-coding">
  <xsl:text>color:</xsl:text>
  <xsl:choose>
   <xsl:when test="p:validity = 'valid'">
    <xsl:value-of select="$vvalid"/>
   </xsl:when>
   <xsl:when test="p:validity = 'invalid'">
    <xsl:value-of select="$vinvalid"/>
   </xsl:when>
   <xsl:when test="p:validity = 'notKnown'">
    <xsl:value-of select="$vunknown"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$vother"/>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:text>; background-color:</xsl:text>
  <xsl:choose>
   <xsl:when test="p:validationAttempted = 'full'">
    <xsl:value-of select="$vafull"/>
   </xsl:when>
   <xsl:when test="p:validationAttempted = 'partial'">
    <xsl:value-of select="$vapart"/>
   </xsl:when>
   <xsl:when test="p:validationAttempted = 'none'">
    <xsl:value-of select="$vanone"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="$vaother"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

<!-- Keep this comment at the end of the file
Local variables:
mode: xml
sgml-default-dtd-file:"/SGML/Public/Emacs/xslt.ced"
sgml-omittag:t
sgml-shorttag:t
sgml-indent-data:t
sgml-indent-step:1
End:
-->

