<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" encoding="ISO-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" indent="yes"/>


<!-- Le cadre HTML -->

<xsl:template match="/">
  <html>
    <head>
      <title>Coloration</title>
      <meta name="robots" content="noindex" />
      <link rel="stylesheet" type="text/css" href="coloration.css" />
    </head>
    <body>
      <div class="encart">	
      <p>
	Cette page est produite dans le cadre d'exercices sur XSLT. Son contenu n'est peut-être pas pertinent.
      </p>
      <ul>
	<li>retour aux <a href="http://www.grappa.univ-lille3.fr/~torre/Enseignement/TPs/XML/Corrections/">solutions des exercices XML</a></li>
	<li>retour aux <a href="http://www.grappa.univ-lille3.fr/~torre/Enseignement/TPs/XML/XSLT/">exercices XSLT</a></li>
	<li>retour à la page de <a href="http://www.grappa.univ-lille3.fr/~torre/">Fabien Torre</a></li>
      </ul>
      </div>
      <div class="instruction">
	&lt;?xml version="1.0" ?&gt;
      </div>
      <xsl:apply-templates />
    </body>
  </html>
</xsl:template>



<!-- Tranformation des éléments -->

<xsl:template name="baliseouvrante">
  <xsl:param name="noeud" />
  <span class="langagexml">&lt;<xsl:value-of select="name($noeud)" /></span>
  <xsl:apply-templates select="$noeud/@*" />
  <span class="langagexml">&gt;</span>
</xsl:template>

<xsl:template name="balisefermante">
  <xsl:param name="noeud" />
  <span class="langagexml">&lt;/<xsl:value-of select="name($noeud)" />&gt;</span>
</xsl:template>

<xsl:template name="baliseouvrantefermante">
  <xsl:param name="noeud" />
  <span class="langagexml">&lt;<xsl:value-of select="name($noeud)" /></span>
  <xsl:apply-templates select="$noeud/@*" />
  <xsl:text disable-output-escaping="yes">&amp;nbsp;/</xsl:text>
  <span class="langagexml">&gt;</span>
</xsl:template>

<xsl:template match="*">
  <xsl:variable name="fils" select="node()" />
  <div class="blocelement">
    <xsl:choose>
      <xsl:when test="count($fils)>0">

	<xsl:variable name="nbtextes" select="count(text()[normalize-space(.) != ''])" />

	<xsl:call-template name="baliseouvrante">
	  <xsl:with-param name="noeud" select="." />
	</xsl:call-template>

	<xsl:choose>

	  <xsl:when test="(count($fils)>=2) and ($nbtextes>=1)">
	    <div class="contenumixte">
	      <xsl:apply-templates mode="mixte" />
	    </div>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:apply-templates />
	  </xsl:otherwise>
	</xsl:choose>

	<xsl:call-template name="balisefermante">
	  <xsl:with-param name="noeud" select="." />
	</xsl:call-template>

      </xsl:when>
      
      <xsl:otherwise>
	
	<xsl:call-template name="baliseouvrantefermante">
	  <xsl:with-param name="noeud" select="." />
	</xsl:call-template>
	
      </xsl:otherwise>

    </xsl:choose>
  </div>
</xsl:template>

<xsl:template match="*" mode="mixte">
  <xsl:variable name="fils" select="node()" />
    <xsl:choose>
      <xsl:when test="count($fils)>0">

	<xsl:call-template name="baliseouvrante">
	  <xsl:with-param name="noeud" select="." />
	</xsl:call-template>

	<xsl:apply-templates mode="mixte" />

	<xsl:call-template name="balisefermante">
	  <xsl:with-param name="noeud" select="." />
	</xsl:call-template>

      </xsl:when>

      <xsl:otherwise>
	<xsl:call-template name="baliseouvrantefermante">
	  <xsl:with-param name="noeud" select="." />
	</xsl:call-template>
      </xsl:otherwise>

    </xsl:choose>
</xsl:template>


<!-- Sortie des attributs -->

<xsl:template match="@*">
    <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
    <xsl:value-of select="name()" />=<span class="valeur">"<xsl:value-of select="." />"</span>
</xsl:template>


<!-- Sortie des commentaires -->

<xsl:template match="comment()">
  <div class="commentaire">
    &lt;!-- <xsl:value-of select="." /> --&gt;
  </div>
</xsl:template>


<!-- Sortie des instructions -->

<xsl:template match="processing-instruction()">
  <div class="instruction">
    &lt;?<xsl:value-of select="name() " /> 
    <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
    <xsl:value-of select="." />?&gt;
  </div>
</xsl:template>



<!-- Sortie des noeuds textuels -->

<xsl:template match="text()">

  <xsl:choose>

    <xsl:when test="string-length(.)>60">
      <div class="texte">
	<xsl:value-of select="." />
      </div>
    </xsl:when>

    <xsl:otherwise>
      <span class="texte"><xsl:value-of select="." /></span>
    </xsl:otherwise>

  </xsl:choose>

</xsl:template>


<xsl:template match="text()" mode="mixte">
  <span class="texte"><xsl:value-of select="." /></span>
</xsl:template>


</xsl:stylesheet>

