XMLPrettyPrint.xsl (4421B)
1 <?xml version="1.0"?> 2 <!-- This Source Code Form is subject to the terms of the Mozilla Public 3 - License, v. 2.0. If a copy of the MPL was not distributed with this 4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 5 6 <!DOCTYPE overlay> 7 8 <xsl:stylesheet version="1.0" 9 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 10 xmlns="http://www.w3.org/1999/xhtml"> 11 12 <xsl:output method="xml"/> 13 14 <xsl:template match="/"> 15 <div id="top"> 16 <link rel="stylesheet" href="chrome://global/content/xml/XMLPrettyPrint.css"/> 17 <div id="header"> 18 <p data-l10n-id="xml-nostylesheet"></p> 19 </div> 20 <main id="tree" class="highlight"> 21 <xsl:apply-templates/> 22 </main> 23 </div> 24 </xsl:template> 25 26 <xsl:template match="*"> 27 <div> 28 <xsl:text><</xsl:text> 29 <span class="start-tag"><xsl:value-of select="name(.)"/></span> 30 <xsl:apply-templates select="@*"/> 31 <xsl:text>/></xsl:text> 32 </div> 33 </xsl:template> 34 35 <xsl:template match="*[node()]"> 36 <div><xsl:apply-templates mode="space" select="@xml:space"/> 37 <xsl:text><</xsl:text> 38 <span class="start-tag"><xsl:value-of select="name(.)"/></span> 39 <xsl:apply-templates select="@*"/> 40 <xsl:text>></xsl:text> 41 42 <span class="text"><xsl:value-of select="."/></span> 43 44 <xsl:text></</xsl:text> 45 <span class="end-tag"><xsl:value-of select="name(.)"/></span> 46 <xsl:text>></xsl:text> 47 </div> 48 </xsl:template> 49 50 <xsl:template match="*[* or processing-instruction() or comment() or string-length(.) > 50]"> 51 <div><xsl:apply-templates mode="space" select="@xml:space"/> 52 <details open="" class="expandable-body"> 53 <summary class="expandable-opening"> 54 <xsl:text><</xsl:text> 55 <span class="start-tag"><xsl:value-of select="name(.)"/></span> 56 <xsl:apply-templates select="@*"/> 57 <xsl:text>></xsl:text> 58 </summary> 59 60 <div class="expandable-children"><xsl:apply-templates/></div> 61 62 </details> 63 <span class="expandable-closing"> 64 <xsl:text></</xsl:text> 65 <span class="end-tag"><xsl:value-of select="name(.)"/></span> 66 <xsl:text>></xsl:text> 67 </span> 68 </div> 69 </xsl:template> 70 71 <xsl:template match="@xml:space[string() = 'default']" mode="space"> 72 <xsl:attribute name="class">space-default</xsl:attribute> 73 </xsl:template> 74 <xsl:template match="@xml:space[string() = 'preserve']" mode="space"> 75 <xsl:attribute name="class">space-preserve</xsl:attribute> 76 </xsl:template> 77 78 <xsl:template match="@*"> 79 <xsl:text> </xsl:text> 80 <span class="attribute-name"><xsl:value-of select="name(.)"/></span> 81 <xsl:text>=</xsl:text> 82 <span class="attribute-value">"<xsl:value-of select="."/>"</span> 83 </xsl:template> 84 85 <xsl:template match="text()"> 86 <xsl:if test="normalize-space(.)"> 87 <xsl:value-of select="."/> 88 </xsl:if> 89 </xsl:template> 90 91 <xsl:template match="processing-instruction()"> 92 <div class="pi"> 93 <xsl:text><?</xsl:text> 94 <xsl:value-of select="name(.)"/> 95 <xsl:text> </xsl:text> 96 <xsl:value-of select="."/> 97 <xsl:text>?></xsl:text> 98 </div> 99 </xsl:template> 100 101 <xsl:template match="processing-instruction()[string-length(.) > 50]"> 102 <div class="pi"> 103 <details open="" class="expandable-body"> 104 <summary class="expandable-opening"> 105 <xsl:text><?</xsl:text> 106 <xsl:value-of select="name(.)"/> 107 </summary> 108 <div class="expandable-children"><xsl:value-of select="."/></div> 109 </details> 110 <span class="expandable-closing"> 111 <xsl:text>?></xsl:text> 112 </span> 113 </div> 114 </xsl:template> 115 116 <xsl:template match="comment()"> 117 <div class="comment"> 118 <xsl:text><!--</xsl:text> 119 <xsl:value-of select="."/> 120 <xsl:text>--></xsl:text> 121 </div> 122 </xsl:template> 123 124 <xsl:template match="comment()[string-length(.) > 50]"> 125 <div class="comment"> 126 <details open="" class="expandable-body"> 127 <summary class="expandable-opening"> 128 <xsl:text><!--</xsl:text> 129 </summary> 130 <div class="expandable-children"> 131 <xsl:value-of select="."/> 132 </div> 133 </details> 134 <span class="expandable-closing"> 135 <xsl:text>--></xsl:text> 136 </span> 137 </div> 138 </xsl:template> 139 140 </xsl:stylesheet>