| 1 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 2 | <?xml-stylesheet type="text/xsl" href="xml.xsl"?>
|
|---|
| 3 | <xsl:stylesheet version="1.0"
|
|---|
| 4 | xmlns="http://www.w3.org/1999/xhtml"
|
|---|
| 5 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|---|
| 6 | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|---|
| 7 | xmlns:cc="http://web.resource.org/cc/"
|
|---|
| 8 | xmlns:my="http://coderepos.org/"
|
|---|
| 9 | exclude-result-prefixes="rdf cc my"
|
|---|
| 10 | xml:lang="ja">
|
|---|
| 11 |
|
|---|
| 12 | <xsl:output
|
|---|
| 13 | method="xml"
|
|---|
| 14 | encoding="UTF-8"
|
|---|
| 15 | omit-xml-declaration="no"
|
|---|
| 16 | doctype-public="-//W3C//DTD XHTML 1.1//EN"
|
|---|
| 17 | doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
|
|---|
| 18 | indent="yes"
|
|---|
| 19 | />
|
|---|
| 20 |
|
|---|
| 21 | <!-- これ以下の文字数のテキストはインライン表示に -->
|
|---|
| 22 | <xsl:param name="shortlen" select="20"/>
|
|---|
| 23 |
|
|---|
| 24 | <xsl:strip-space elements="*" />
|
|---|
| 25 |
|
|---|
| 26 | <xsl:template name="my:cho45.css">
|
|---|
| 27 | <xsl:text><![CDATA[
|
|---|
| 28 | * {
|
|---|
| 29 | margin: 0;
|
|---|
| 30 | padding: 0;
|
|---|
| 31 | text-decoration: none;
|
|---|
| 32 | font-size: 100%;
|
|---|
| 33 | font-weight: normal;
|
|---|
| 34 | font-style: normal;
|
|---|
| 35 | background: transparent;
|
|---|
| 36 | border: none;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | body {
|
|---|
| 40 | font-family: "Verdana", "Helvetica", sans-serif;
|
|---|
| 41 | background: #000;
|
|---|
| 42 | color: #fff;
|
|---|
| 43 | padding: 0;
|
|---|
| 44 | margin: 0;
|
|---|
| 45 | line-height: 1.4;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | h1 {
|
|---|
| 49 | font-size: 100%;
|
|---|
| 50 | background: #c80055;
|
|---|
| 51 | margin: 0;
|
|---|
| 52 | padding: 0.5em;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | p {
|
|---|
| 56 | margin: 0;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | #tree {
|
|---|
| 60 | padding: 2em 1em;
|
|---|
| 61 | margin: 0;
|
|---|
| 62 | border-style: solid;
|
|---|
| 63 | border-width: 0 0 0 2em;
|
|---|
| 64 | border-color: #1b261d;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | #info {
|
|---|
| 68 | background: #c80055;
|
|---|
| 69 | margin: 0 0 0 0;
|
|---|
| 70 | padding: 1em;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | .paren {
|
|---|
| 74 | color: #72655b;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | .content {
|
|---|
| 78 | margin: 0 0 0 2em;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | .ename {
|
|---|
| 82 | color: #c80055;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | .attrn {
|
|---|
| 86 | color: #ab5a39;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | .attrv {
|
|---|
| 90 | color: #4e6443;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | .attrv a {
|
|---|
| 94 | color: #4e6443;
|
|---|
| 95 | text-decoration: none;
|
|---|
| 96 | border-bottom: 1px dotted;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | .attrv a:hover {
|
|---|
| 100 | color: #4e6443;
|
|---|
| 101 | text-decoration: none;
|
|---|
| 102 | border-bottom: none;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | .comment {
|
|---|
| 106 | color: #999;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | .pi {
|
|---|
| 110 | color: #993;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | .text {
|
|---|
| 114 | color: #70645a;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | .less {
|
|---|
| 118 | }
|
|---|
| 119 | .less a {
|
|---|
| 120 | }
|
|---|
| 121 | ]]></xsl:text>
|
|---|
| 122 | </xsl:template>
|
|---|
| 123 |
|
|---|
| 124 | <xsl:template match="/">
|
|---|
| 125 | <html xml:lang="{/*[position() = 1]/@xml:lang}">
|
|---|
| 126 | <head>
|
|---|
| 127 | <title>
|
|---|
| 128 | <xsl:value-of select="name(*)"/>
|
|---|
| 129 | <xsl:text> - </xsl:text>
|
|---|
| 130 | <xsl:text>XML document</xsl:text>
|
|---|
| 131 | </title>
|
|---|
| 132 | <style type="text/css">
|
|---|
| 133 | <xsl:call-template name="my:cho45.css"/>
|
|---|
| 134 | </style>
|
|---|
| 135 | </head>
|
|---|
| 136 |
|
|---|
| 137 | <body>
|
|---|
| 138 | <h1>
|
|---|
| 139 | <xsl:value-of select="name(*)"/>
|
|---|
| 140 | <xsl:text> - </xsl:text>
|
|---|
| 141 | <abbr title="Extensible Markup Language">XML</abbr>
|
|---|
| 142 | <xsl:text> document</xsl:text>
|
|---|
| 143 | <!-- <xsl:value-of select="string(namespace-uri(//*))"/> -->
|
|---|
| 144 | </h1>
|
|---|
| 145 | <div id="tree">
|
|---|
| 146 | <xsl:apply-templates mode="my:tree.xhtml"/>
|
|---|
| 147 | </div>
|
|---|
| 148 | <div id="info">
|
|---|
| 149 | <p>
|
|---|
| 150 | <strong><xsl:value-of select="count(//node()) + count(//@node())"/></strong>
|
|---|
| 151 | <xsl:text> nodes. ( </xsl:text>
|
|---|
| 152 | <strong><xsl:value-of select="count(//*)"/></strong><xsl:text> elements. </xsl:text>
|
|---|
| 153 | <strong><xsl:value-of select="count(//@node())"/></strong><xsl:text> attributes. </xsl:text>
|
|---|
| 154 | <strong><xsl:value-of select="count(//text())"/></strong><xsl:text> texts. </xsl:text>
|
|---|
| 155 | <strong><xsl:value-of select="count(//comment())"/></strong><xsl:text> comments. </xsl:text>
|
|---|
| 156 | <strong><xsl:value-of select="count(//processing-instruction())"/></strong><xsl:text> processing-instructions. )</xsl:text>
|
|---|
| 157 | </p>
|
|---|
| 158 | <p class="less">
|
|---|
| 159 | xsl:version: <xsl:value-of select="format-number(system-property('xsl:version'), '0.0')"/>,
|
|---|
| 160 | xsl:vendor:
|
|---|
| 161 | <xsl:value-of select="system-property('xsl:vendor')"/> -
|
|---|
| 162 | <xsl:value-of select="system-property('xsl:vendor-url')"/>
|
|---|
| 163 | </p>
|
|---|
| 164 | </div>
|
|---|
| 165 | </body>
|
|---|
| 166 | </html>
|
|---|
| 167 | </xsl:template>
|
|---|
| 168 |
|
|---|
| 169 | <!-- msxml は空白にうるさいので少し見にくい。 -->
|
|---|
| 170 |
|
|---|
| 171 | <xsl:template match="*" mode="my:tree.xhtml">
|
|---|
| 172 | <div class="element">
|
|---|
| 173 | <xsl:choose>
|
|---|
| 174 | <xsl:when test=". = '' and count(*) = 0">
|
|---|
| 175 | <span class="paren"><</span><span class="ename"><xsl:value-of select="name()" /></span>
|
|---|
| 176 | <xsl:apply-templates select="@*" mode="my:tree.xhtml"/>
|
|---|
| 177 | <span class="paren">/></span>
|
|---|
| 178 | </xsl:when>
|
|---|
| 179 | <xsl:otherwise>
|
|---|
| 180 | <span class="paren"><</span>
|
|---|
| 181 | <span class="ename"><xsl:value-of select="name()" /></span>
|
|---|
| 182 | <xsl:apply-templates select="@*" mode="my:tree.xhtml"/>
|
|---|
| 183 | <span class="paren">></span>
|
|---|
| 184 | <xsl:choose>
|
|---|
| 185 | <xsl:when test="string-length() < $shortlen and count(*) = 0">
|
|---|
| 186 | <xsl:apply-templates mode="my:tree.xhtml"/>
|
|---|
| 187 | </xsl:when>
|
|---|
| 188 | <xsl:otherwise>
|
|---|
| 189 | <div class="content">
|
|---|
| 190 | <xsl:apply-templates mode="my:tree.xhtml"/>
|
|---|
| 191 | </div>
|
|---|
| 192 | </xsl:otherwise>
|
|---|
| 193 | </xsl:choose>
|
|---|
| 194 | <span class="paren"><</span><span class="ename"><xsl:text>/</xsl:text><xsl:value-of select="name()" /></span><span class="paren">></span>
|
|---|
| 195 | </xsl:otherwise>
|
|---|
| 196 | </xsl:choose>
|
|---|
| 197 | </div>
|
|---|
| 198 | </xsl:template>
|
|---|
| 199 |
|
|---|
| 200 | <xsl:template match="@*" mode="my:tree.xhtml">
|
|---|
| 201 | <xsl:text> </xsl:text>
|
|---|
| 202 | <span class="attrn">
|
|---|
| 203 | <xsl:value-of select="name()" />
|
|---|
| 204 | <xsl:text>=</xsl:text>
|
|---|
| 205 | </span>
|
|---|
| 206 | <span class="attrv">
|
|---|
| 207 | <xsl:text>"</xsl:text>
|
|---|
| 208 | <xsl:choose>
|
|---|
| 209 | <!-- for XHTML, RDF -->
|
|---|
| 210 | <xsl:when test="
|
|---|
| 211 | local-name() = 'href' or
|
|---|
| 212 | local-name() = 'resource' or
|
|---|
| 213 | local-name() = 'about'">
|
|---|
| 214 | <a href="{.}">
|
|---|
| 215 | <xsl:call-template name="my:entity">
|
|---|
| 216 | <xsl:with-param name="string" select="."/>
|
|---|
| 217 | </xsl:call-template>
|
|---|
| 218 | </a>
|
|---|
| 219 | </xsl:when>
|
|---|
| 220 | <xsl:otherwise>
|
|---|
| 221 | <xsl:call-template name="my:entity">
|
|---|
| 222 | <xsl:with-param name="string" select="."/>
|
|---|
| 223 | </xsl:call-template>
|
|---|
| 224 | </xsl:otherwise>
|
|---|
| 225 | </xsl:choose>
|
|---|
| 226 | <xsl:text>"</xsl:text>
|
|---|
| 227 | </span>
|
|---|
| 228 | </xsl:template>
|
|---|
| 229 |
|
|---|
| 230 | <xsl:template match="comment()" mode="my:tree.xhtml">
|
|---|
| 231 | <div class="element comment">
|
|---|
| 232 | <xsl:text><!--</xsl:text>
|
|---|
| 233 | <xsl:value-of select="."/>
|
|---|
| 234 | <xsl:text>--></xsl:text>
|
|---|
| 235 | </div>
|
|---|
| 236 | </xsl:template>
|
|---|
| 237 |
|
|---|
| 238 | <xsl:template match="processing-instruction()" mode="my:tree.xhtml">
|
|---|
| 239 | <div class="element pi">
|
|---|
| 240 | <xsl:text><?</xsl:text>
|
|---|
| 241 | <xsl:value-of select="name()" />
|
|---|
| 242 | <xsl:text> </xsl:text>
|
|---|
| 243 | <xsl:value-of select="."/>
|
|---|
| 244 | <xsl:text>?></xsl:text>
|
|---|
| 245 | </div>
|
|---|
| 246 | </xsl:template>
|
|---|
| 247 |
|
|---|
| 248 | <xsl:template match="text()" mode="my:tree.xhtml">
|
|---|
| 249 | <span class="text">
|
|---|
| 250 | <xsl:call-template name="my:entity">
|
|---|
| 251 | <xsl:with-param name="string" select="."/>
|
|---|
| 252 | </xsl:call-template>
|
|---|
| 253 | </span>
|
|---|
| 254 | </xsl:template>
|
|---|
| 255 |
|
|---|
| 256 | <!-- & > < 変換 -->
|
|---|
| 257 | <xsl:template name="my:entity">
|
|---|
| 258 | <xsl:param name="string" />
|
|---|
| 259 | <xsl:choose>
|
|---|
| 260 | <xsl:when test="contains($string, '&')">
|
|---|
| 261 | <xsl:call-template name="my:entity2">
|
|---|
| 262 | <xsl:with-param name="string" select="substring-before($string, '&')" />
|
|---|
| 263 | </xsl:call-template>
|
|---|
| 264 | <xsl:text>&amp;</xsl:text>
|
|---|
| 265 | <xsl:call-template name="my:entity">
|
|---|
| 266 | <xsl:with-param name="string" select="substring-after($string, '&')" />
|
|---|
| 267 | </xsl:call-template>
|
|---|
| 268 | </xsl:when>
|
|---|
| 269 | <xsl:otherwise>
|
|---|
| 270 | <xsl:call-template name="my:entity2">
|
|---|
| 271 | <xsl:with-param name="string" select="$string" />
|
|---|
| 272 | </xsl:call-template>
|
|---|
| 273 | </xsl:otherwise>
|
|---|
| 274 | </xsl:choose>
|
|---|
| 275 | </xsl:template>
|
|---|
| 276 |
|
|---|
| 277 | <xsl:template name="my:entity2">
|
|---|
| 278 | <xsl:param name="string" />
|
|---|
| 279 | <xsl:choose>
|
|---|
| 280 | <xsl:when test="contains($string, '<') or contains($string, '>')">
|
|---|
| 281 | <xsl:choose>
|
|---|
| 282 | <xsl:when test="contains($string, '<')">
|
|---|
| 283 | <xsl:if test="contains($string, '<')">
|
|---|
| 284 | <xsl:variable name="nstr"><xsl:value-of select="substring-before($string, '<')"/><xsl:text>&lt;</xsl:text><xsl:value-of select="substring-after($string, '<')"/></xsl:variable>
|
|---|
| 285 | <xsl:call-template name="my:entity2">
|
|---|
| 286 | <xsl:with-param name="string" select="$nstr"/>
|
|---|
| 287 | </xsl:call-template>
|
|---|
| 288 | </xsl:if>
|
|---|
| 289 | </xsl:when>
|
|---|
| 290 | <xsl:when test="contains($string, '>')">
|
|---|
| 291 | <xsl:if test="contains($string, '>')">
|
|---|
| 292 | <xsl:variable name="nstr"><xsl:value-of select="substring-before($string, '>')"/><xsl:text>&gt;</xsl:text><xsl:value-of select="substring-after($string, '>')"/></xsl:variable>
|
|---|
| 293 | <xsl:call-template name="my:entity2">
|
|---|
| 294 | <xsl:with-param name="string" select="$nstr"/>
|
|---|
| 295 | </xsl:call-template>
|
|---|
| 296 | </xsl:if>
|
|---|
| 297 | </xsl:when>
|
|---|
| 298 | </xsl:choose>
|
|---|
| 299 | </xsl:when>
|
|---|
| 300 | <xsl:otherwise>
|
|---|
| 301 | <xsl:value-of select="$string"/>
|
|---|
| 302 | </xsl:otherwise>
|
|---|
| 303 | </xsl:choose>
|
|---|
| 304 | </xsl:template>
|
|---|
| 305 |
|
|---|
| 306 | </xsl:stylesheet>
|
|---|