<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/xhtml">
<xsl:param name="title"/>
  <xsl:output method="xml" indent="yes"/>
    
    <xsl:variable name="debug" select="'false'"/>

  <xsl:template match="/">
    <!--link href="http://global/content/xml/XMLPrettyPrint.css" type="text/css" rel="stylesheet"/>
    <link title="Monospace" href="http://global/content/xml/XMLMonoPrint.css" type="text/css" rel="alternate stylesheet"/>
    <div id="header">
      <p>
        &xml.nostylesheet;
      </p>
      </div-->
    <html>
      <head>
        <title>Source XML de <xsl:value-of select="$title"/></title>
        <style type="text/css">
          span { font-family: monospace; font-size: 12px; }
          .expander-content {
          padding-left: 1em;
          }
          
          .expander {
          text-align: center;
          vertical-align: top;
          width: 1em;
          display: inline-block;
          margin-left: -1em;
          }
          
          #top > .expander-open, #top > .expander-closed {
          margin-left: 1em;
          }
          
          .expander-closed > .expander-content {
          display: none;
          }
          .comment {
          font-family: monospace;
          font-size: 12px;
          white-space: pre;
          }
          #top > .expander-open {
          font-family: monospace;
          font-size: 12px;
          white-space: pre;
          }
          *|*:root {
          background-color: white;
          }
          #viewsource {
          font-family: monospace;
          font-size: 12px;
          font-weight: normal;
          color: black;
          white-space: pre;
          }
          #viewsource.wrap {
          white-space: pre-wrap;
          }
          pre {
          font: inherit;
          color: inherit;
          white-space: inherit; 
          margin: 0;
          }
          .start-tag {
          color: purple;
          font-weight: bold;
          font-size: 12px;
          }
          .end-tag {
          color: purple;
          font-weight: bold;
          font-size: 12px;
          }
          .comment {
          color: green;
          font-style: italic;
          }
          .cdata {
          color: #CC0066;
          }
          .doctype {
          color: steelblue;
          font-style: italic;
          }
          .pi {
          color: orchid;
          font-style: italic;
          }
          .entity {
          color:#FF4500;
          font-weight: normal;
          }
          .text {
          font-weight: normal;
          }
          .attribute-name {
          color: black;
          font-weight: bold;
          }
          .attribute-value {
          color: blue;
          font-weight: normal;
          }
          .summary {
          display: block;
          background-color: #FFFFCC;
          width: 90%;
          border: solid;
          border-width: 1pt;
          font-family: sans-serif;
          }
          .popup {
          font-weight: normal;
          }
          .markupdeclaration {
          color: steelblue;
          font-style: italic;
          }
          .error, .error > .start-tag, .error > .end-tag,
          .error > .comment, .error > .cdata, .error > .doctype,
          .error > .pi, .error > .entity, .error > .attribute-name,
          .error > .attribute-value {
          color: red;
          font-weight: bold;
          }
        </style>
      </head>
      <body><xsl:apply-templates/></body>
    </html>
  </xsl:template>

  <xsl:template match="*">
    <xsl:if test="not(namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#added' or namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#anomally' or starts-with(local-name(.),'added:') or starts-with(local-name(.),'ano:')) or $debug='true'">
      <div>
      <xsl:text>&lt;</xsl:text>
      <span class="start-tag"><xsl:value-of select="name(.)"/></span>
      <xsl:apply-templates select="@*"/>
      <xsl:text>/&gt;</xsl:text>
      </div>
      </xsl:if>
  </xsl:template>

  <xsl:template match="*[node()]">
    <xsl:if test="not(namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#added' or namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#anomally' or starts-with(local-name(.),'added:') or starts-with(local-name(.),'ano:')) or $debug='true'">
    <div>
      <xsl:text>&lt;</xsl:text>
      <span class="start-tag"><xsl:value-of select="name(.)"/></span>
      <xsl:apply-templates select="@*"/>
      <xsl:text>&gt;</xsl:text>

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

      <xsl:text>&lt;/</xsl:text>
      <span class="end-tag"><xsl:value-of select="name(.)"/></span>
      <xsl:text>&gt;</xsl:text>
    </div>
    </xsl:if>
  </xsl:template>

  <xsl:template match="*[* or processing-instruction() or comment() or string-length(.) &gt; 50]">
    <xsl:if test="not(namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#added' or namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#anomally' or starts-with(local-name(.),'added:') or starts-with(local-name(.),'ano:')) or $debug='true'">
      <div class="expander-open">
      <xsl:call-template name="expander"/>

      <xsl:text>&lt;</xsl:text>
      <span class="start-tag"><xsl:value-of select="name(.)"/></span>
      <xsl:apply-templates select="@*"/>
      <xsl:text>&gt;</xsl:text>

      <div class="expander-content"><xsl:apply-templates/></div>

      <xsl:text>&lt;/</xsl:text>
      <span class="end-tag"><xsl:value-of select="name(.)"/></span>
      <xsl:text>&gt;</xsl:text>
      </div>
      </xsl:if>
  </xsl:template>

  <xsl:template match="@*">
    <xsl:if test="not(namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#added' or namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#anomally' or starts-with(local-name(.),'added:') or starts-with(local-name(.),'ano:')) or $debug='true'">
      <xsl:text> </xsl:text>
    <span class="attribute-name"><xsl:value-of select="name(.)"/></span>
    <xsl:text>=</xsl:text>
    <span class="attribute-value">"<xsl:value-of select="."/>"</span>
    </xsl:if>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:if test="normalize-space(.)">
      <xsl:value-of select="."/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="processing-instruction()">
    <div class="pi">
      <xsl:text>&lt;?</xsl:text>
      <xsl:value-of select="name(.)"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>?&gt;</xsl:text>
    </div>
  </xsl:template>

  <xsl:template match="processing-instruction()[string-length(.) &gt; 50]">
    <div class="expander-open">
      <xsl:call-template name="expander"/>

      <span class="pi">
        <xsl:text> &lt;?</xsl:text>
        <xsl:value-of select="name(.)"/>
      </span>
      <div class="expander-content pi"><xsl:value-of select="."/></div>
      <span class="pi">
        <xsl:text>?&gt;</xsl:text>
      </span>
    </div>
  </xsl:template>

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

  <xsl:template match="comment()[string-length(.) &gt; 50]">
    <div class="expander-open">
      <xsl:call-template name="expander"/>

      <span class="comment">
        <xsl:text>&lt;!--</xsl:text>
      </span>
      <div class="expander-content comment">
        <xsl:value-of select="."/>
      </div>
      <span class="comment">
        <xsl:text>--&gt;</xsl:text>
      </span> 
    </div>
  </xsl:template>
  
  <xsl:template name="expander">
    <!--div class="expander">&#x2212;</div-->
  </xsl:template>

</xsl:stylesheet>
