content/xml/document/resources/XMLPrettyPrint.xsl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xml/document/resources/XMLPrettyPrint.xsl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.8 +
     1.9 +<!DOCTYPE overlay [
    1.10 +  <!ENTITY % prettyPrintDTD SYSTEM "chrome://global/locale/xml/prettyprint.dtd">
    1.11 +  %prettyPrintDTD;
    1.12 +  <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
    1.13 +  %globalDTD;
    1.14 +]>
    1.15 +
    1.16 +<xsl:stylesheet version="1.0"
    1.17 +                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    1.18 +                xmlns="http://www.w3.org/1999/xhtml">
    1.19 +
    1.20 +  <xsl:output method="xml"/>
    1.21 +
    1.22 +  <xsl:template match="/">
    1.23 +    <link href="chrome://global/content/xml/XMLPrettyPrint.css" type="text/css" rel="stylesheet"/>
    1.24 +    <link title="Monospace" href="chrome://global/content/xml/XMLMonoPrint.css" type="text/css" rel="alternate stylesheet"/>
    1.25 +    <div id="header" dir="&locale.dir;">
    1.26 +      <p>
    1.27 +        &xml.nostylesheet;
    1.28 +      </p>
    1.29 +    </div>
    1.30 +    <xsl:apply-templates/>
    1.31 +  </xsl:template>
    1.32 +
    1.33 +  <xsl:template match="*">
    1.34 +    <div>
    1.35 +      <xsl:text>&lt;</xsl:text>
    1.36 +      <span class="start-tag"><xsl:value-of select="name(.)"/></span>
    1.37 +      <xsl:apply-templates select="@*"/>
    1.38 +      <xsl:text>/&gt;</xsl:text>
    1.39 +    </div>
    1.40 +  </xsl:template>
    1.41 +
    1.42 +  <xsl:template match="*[node()]">
    1.43 +    <div>
    1.44 +      <xsl:text>&lt;</xsl:text>
    1.45 +      <span class="start-tag"><xsl:value-of select="name(.)"/></span>
    1.46 +      <xsl:apply-templates select="@*"/>
    1.47 +      <xsl:text>&gt;</xsl:text>
    1.48 +
    1.49 +      <span class="text"><xsl:value-of select="."/></span>
    1.50 +
    1.51 +      <xsl:text>&lt;/</xsl:text>
    1.52 +      <span class="end-tag"><xsl:value-of select="name(.)"/></span>
    1.53 +      <xsl:text>&gt;</xsl:text>
    1.54 +    </div>
    1.55 +  </xsl:template>
    1.56 +
    1.57 +  <xsl:template match="*[* or processing-instruction() or comment() or string-length(.) &gt; 50]">
    1.58 +    <div class="expander-open">
    1.59 +      <xsl:call-template name="expander"/>
    1.60 +
    1.61 +      <xsl:text>&lt;</xsl:text>
    1.62 +      <span class="start-tag"><xsl:value-of select="name(.)"/></span>
    1.63 +      <xsl:apply-templates select="@*"/>
    1.64 +      <xsl:text>&gt;</xsl:text>
    1.65 +
    1.66 +      <div class="expander-content"><xsl:apply-templates/></div>
    1.67 +
    1.68 +      <xsl:text>&lt;/</xsl:text>
    1.69 +      <span class="end-tag"><xsl:value-of select="name(.)"/></span>
    1.70 +      <xsl:text>&gt;</xsl:text>
    1.71 +    </div>
    1.72 +  </xsl:template>
    1.73 +
    1.74 +  <xsl:template match="@*">
    1.75 +    <xsl:text> </xsl:text>
    1.76 +    <span class="attribute-name"><xsl:value-of select="name(.)"/></span>
    1.77 +    <xsl:text>=</xsl:text>
    1.78 +    <span class="attribute-value">"<xsl:value-of select="."/>"</span>
    1.79 +  </xsl:template>
    1.80 +
    1.81 +  <xsl:template match="text()">
    1.82 +    <xsl:if test="normalize-space(.)">
    1.83 +      <xsl:value-of select="."/>
    1.84 +    </xsl:if>
    1.85 +  </xsl:template>
    1.86 +
    1.87 +  <xsl:template match="processing-instruction()">
    1.88 +    <div class="pi">
    1.89 +      <xsl:text>&lt;?</xsl:text>
    1.90 +      <xsl:value-of select="name(.)"/>
    1.91 +      <xsl:text> </xsl:text>
    1.92 +      <xsl:value-of select="."/>
    1.93 +      <xsl:text>?&gt;</xsl:text>
    1.94 +    </div>
    1.95 +  </xsl:template>
    1.96 +
    1.97 +  <xsl:template match="processing-instruction()[string-length(.) &gt; 50]">
    1.98 +    <div class="expander-open">
    1.99 +      <xsl:call-template name="expander"/>
   1.100 +
   1.101 +      <span class="pi">
   1.102 +        <xsl:text> &lt;?</xsl:text>
   1.103 +        <xsl:value-of select="name(.)"/>
   1.104 +      </span>
   1.105 +      <div class="expander-content pi"><xsl:value-of select="."/></div>
   1.106 +      <span class="pi">
   1.107 +        <xsl:text>?&gt;</xsl:text>
   1.108 +      </span>
   1.109 +    </div>
   1.110 +  </xsl:template>
   1.111 +
   1.112 +  <xsl:template match="comment()">
   1.113 +    <div class="comment">
   1.114 +      <xsl:text>&lt;!--</xsl:text>
   1.115 +      <xsl:value-of select="."/>
   1.116 +      <xsl:text>--&gt;</xsl:text>
   1.117 +    </div>
   1.118 +  </xsl:template>
   1.119 +
   1.120 +  <xsl:template match="comment()[string-length(.) &gt; 50]">
   1.121 +    <div class="expander-open">
   1.122 +      <xsl:call-template name="expander"/>
   1.123 +
   1.124 +      <span class="comment">
   1.125 +        <xsl:text>&lt;!--</xsl:text>
   1.126 +      </span>
   1.127 +      <div class="expander-content comment">
   1.128 +        <xsl:value-of select="."/>
   1.129 +      </div>
   1.130 +      <span class="comment">
   1.131 +        <xsl:text>--&gt;</xsl:text>
   1.132 +      </span> 
   1.133 +    </div>
   1.134 +  </xsl:template>
   1.135 +  
   1.136 +  <xsl:template name="expander">
   1.137 +    <div class="expander">&#x2212;</div>
   1.138 +  </xsl:template>
   1.139 +
   1.140 +</xsl:stylesheet>

mercurial