Changeset 8401 for lang/xslt

Show
Ignore:
Timestamp:
03/26/08 21:03:30 (5 years ago)
Author:
orzccc
Message:

added namespace to templates for modularization

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/xslt/misc/xml.xsl

    r262 r8401  
    66        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    77        xmlns:cc="http://web.resource.org/cc/" 
    8         exclude-result-prefixes="rdf cc" 
     8        xmlns:my="http://coderepos.org/" 
     9        exclude-result-prefixes="rdf cc my" 
    910        xml:lang="ja"> 
    1011 
     
    2223 
    2324        <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 
    24124        <xsl:template match="/"> 
    25125                <html xml:lang="{/*[position() = 1]/@xml:lang}"> 
     
    31131                                </title> 
    32132                                <style type="text/css"> 
    33                                         <![CDATA[ 
    34                                                 * { 
    35                                                         margin: 0; 
    36                                                         padding: 0; 
    37                                                         text-decoration: none; 
    38                                                         font-size: 100%; 
    39                                                         font-weight: normal; 
    40                                                         font-style: normal; 
    41                                                         background: transparent; 
    42                                                         border: none; 
    43                                                 } 
    44  
    45                                                 body { 
    46                                                         font-family: "Verdana", "Helvetica", sans-serif; 
    47                                                         background: #000; 
    48                                                         color: #fff; 
    49                                                         padding: 0; 
    50                                                         margin: 0; 
    51                                                         line-height: 1.4; 
    52                                                 } 
    53  
    54                                                 h1 { 
    55                                                         font-size: 100%; 
    56                                                         background: #c80055; 
    57                                                         margin: 0; 
    58                                                         padding: 0.5em; 
    59                                                 } 
    60  
    61                                                 p { 
    62                                                         margin: 0; 
    63                                                 } 
    64  
    65                                                 #tree { 
    66                                                         padding: 2em 1em; 
    67                                                         margin: 0; 
    68                                                         border-style: solid; 
    69                                                         border-width: 0 0 0 2em; 
    70                                                         border-color: #1b261d; 
    71                                                 } 
    72  
    73                                                 #info { 
    74                                                         background: #c80055; 
    75                                                         margin: 0 0 0 0; 
    76                                                         padding: 1em; 
    77                                                 } 
    78  
    79                                                 .paren { 
    80                                                         color: #72655b; 
    81                                                 } 
    82  
    83                                                 .content { 
    84                                                         margin: 0 0 0 2em; 
    85                                                 } 
    86  
    87                                                 .ename { 
    88                                                         color: #c80055; 
    89                                                 } 
    90  
    91                                                 .attrn { 
    92                                                         color: #ab5a39; 
    93                                                 } 
    94  
    95                                                 .attrv { 
    96                                                         color: #4e6443; 
    97                                                 } 
    98  
    99                                                 .attrv a { 
    100                                                         color: #4e6443; 
    101                                                         text-decoration: none; 
    102                                                         border-bottom: 1px dotted; 
    103                                                 } 
    104  
    105                                                 .attrv a:hover { 
    106                                                         color: #4e6443; 
    107                                                         text-decoration: none; 
    108                                                         border-bottom: none; 
    109                                                 } 
    110  
    111                                                 .comment { 
    112                                                         color: #999; 
    113                                                 } 
    114  
    115                                                 .pi { 
    116                                                         color: #993; 
    117                                                 } 
    118  
    119                                                 .text { 
    120                                                         color: #70645a; 
    121                                                 } 
    122  
    123                                                 .less { 
    124                                                 } 
    125                                                 .less a { 
    126                                                 } 
    127                                                 ]]> 
     133                                        <xsl:call-template name="my:cho45.css"/> 
    128134                                </style> 
    129135                        </head> 
     
    138144                                </h1> 
    139145                                <div id="tree"> 
    140                                         <xsl:apply-templates /> 
     146                                        <xsl:apply-templates mode="my:tree.xhtml"/> 
    141147                                </div> 
    142148                                <div id="info"> 
     
    163169        <!-- msxml は空白にうるさいので少し見にくい。 --> 
    164170 
    165         <xsl:template match="*"> 
     171        <xsl:template match="*" mode="my:tree.xhtml"> 
    166172                <div class="element"> 
    167173                        <xsl:choose> 
    168174                                <xsl:when test=". = '' and count(*) = 0"> 
    169                                         <span class="paren">&lt;</span><span class="ename"><xsl:value-of select="name()" /></span><xsl:apply-templates select="@*"/><span class="paren">/&gt;</span> 
     175                                        <span class="paren">&lt;</span><span class="ename"><xsl:value-of select="name()" /></span> 
     176                                        <xsl:apply-templates select="@*" mode="my:tree.xhtml"/> 
     177                                        <span class="paren">/&gt;</span> 
    170178                                </xsl:when> 
    171179                                <xsl:otherwise> 
    172                                         <span class="paren">&lt;</span><span class="ename"><xsl:value-of select="name()" /></span><xsl:apply-templates select="@*"/><span class="paren">&gt;</span> 
     180                                        <span class="paren">&lt;</span> 
     181                                        <span class="ename"><xsl:value-of select="name()" /></span> 
     182                                        <xsl:apply-templates select="@*" mode="my:tree.xhtml"/> 
     183                                        <span class="paren">&gt;</span> 
    173184                                        <xsl:choose> 
    174185                                                <xsl:when test="string-length() &lt; $shortlen and count(*) = 0"> 
    175                                                         <xsl:apply-templates/> 
     186                                                        <xsl:apply-templates mode="my:tree.xhtml"/> 
    176187                                                </xsl:when> 
    177188                                                <xsl:otherwise> 
    178189                                                        <div class="content"> 
    179                                                                 <xsl:apply-templates/> 
     190                                                                <xsl:apply-templates mode="my:tree.xhtml"/> 
    180191                                                        </div> 
    181192                                                </xsl:otherwise> 
     
    187198        </xsl:template> 
    188199 
    189         <xsl:template match="@*"> 
     200        <xsl:template match="@*" mode="my:tree.xhtml"> 
    190201                <xsl:text> </xsl:text> 
    191202                <span class="attrn"> 
    192203                        <xsl:value-of select="name()" /> 
    193204                        <xsl:text>=</xsl:text> 
    194                 </span><span class="attrv"> 
     205                </span> 
     206                <span class="attrv"> 
    195207                        <xsl:text>"</xsl:text> 
    196208                        <xsl:choose> 
     
    200212                                        local-name() = 'resource' or 
    201213                                        local-name() = 'about'"> 
    202                                         <a href="{.}"><xsl:call-template name="entity"><xsl:with-param name="string" select="."/></xsl:call-template></a> 
     214                                        <a href="{.}"> 
     215                                                <xsl:call-template name="my:entity"> 
     216                                                        <xsl:with-param name="string" select="."/> 
     217                                                </xsl:call-template> 
     218                                        </a> 
    203219                                </xsl:when> 
    204220                                <xsl:otherwise> 
    205                                         <xsl:call-template name="entity"><xsl:with-param name="string" select="."/></xsl:call-template> 
     221                                        <xsl:call-template name="my:entity"> 
     222                                                <xsl:with-param name="string" select="."/> 
     223                                        </xsl:call-template> 
    206224                                </xsl:otherwise> 
    207225                        </xsl:choose> 
    208                         <xsl:text>"</xsl:text></span> 
    209         </xsl:template> 
    210  
    211         <xsl:template match="comment()"> 
     226                        <xsl:text>"</xsl:text> 
     227                </span> 
     228        </xsl:template> 
     229 
     230        <xsl:template match="comment()" mode="my:tree.xhtml"> 
    212231                <div class="element comment"> 
    213                         <xsl:text>&lt;!--</xsl:text><xsl:value-of select="."/><xsl:text>--&gt;</xsl:text> 
     232                        <xsl:text>&lt;!--</xsl:text> 
     233                        <xsl:value-of select="."/> 
     234                        <xsl:text>--&gt;</xsl:text> 
    214235                </div> 
    215236        </xsl:template> 
    216237 
    217         <xsl:template match="processing-instruction()"> 
     238        <xsl:template match="processing-instruction()" mode="my:tree.xhtml"> 
    218239                <div class="element pi"> 
    219                         <xsl:text>&lt;?</xsl:text><xsl:value-of select="name()" /><xsl:text> </xsl:text><xsl:value-of select="."/><xsl:text>?&gt;</xsl:text> 
     240                        <xsl:text>&lt;?</xsl:text> 
     241                        <xsl:value-of select="name()" /> 
     242                        <xsl:text> </xsl:text> 
     243                        <xsl:value-of select="."/> 
     244                        <xsl:text>?&gt;</xsl:text> 
    220245                </div> 
    221246        </xsl:template> 
    222247 
    223         <xsl:template match="text()"> 
    224                 <span class="text"><xsl:call-template name="entity"><xsl:with-param name="string" select="."/></xsl:call-template></span> 
     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> 
    225254        </xsl:template> 
    226255 
    227256        <!-- &amp; &gt; &lt; 変換 --> 
    228         <xsl:template name="entity"> 
     257        <xsl:template name="my:entity"> 
    229258                <xsl:param name="string" /> 
    230259                <xsl:choose> 
    231260                        <xsl:when test="contains($string, '&amp;')"> 
    232                                 <xsl:call-template name="entity2"> 
     261                                <xsl:call-template name="my:entity2"> 
    233262                                        <xsl:with-param name="string" select="substring-before($string, '&amp;')" /> 
    234263                                </xsl:call-template> 
    235                                 <xsl:text>&amp;amp;</xsl:text><xsl:call-template name="entity"> 
     264                                <xsl:text>&amp;amp;</xsl:text> 
     265                                <xsl:call-template name="my:entity"> 
    236266                                        <xsl:with-param name="string" select="substring-after($string, '&amp;')" /> 
    237267                                </xsl:call-template> 
    238268                        </xsl:when> 
    239269                        <xsl:otherwise> 
    240                                 <xsl:call-template name="entity2"> 
     270                                <xsl:call-template name="my:entity2"> 
    241271                                        <xsl:with-param name="string" select="$string" /> 
    242272                                </xsl:call-template> 
     
    245275        </xsl:template> 
    246276 
    247         <xsl:template name="entity2"> 
     277        <xsl:template name="my:entity2"> 
    248278                <xsl:param name="string" /> 
    249279                <xsl:choose> 
     
    253283                                                <xsl:if test="contains($string, '&lt;')"> 
    254284                                                        <xsl:variable name="nstr"><xsl:value-of select="substring-before($string, '&lt;')"/><xsl:text>&amp;lt;</xsl:text><xsl:value-of select="substring-after($string, '&lt;')"/></xsl:variable> 
    255                                                         <xsl:call-template name="entity2"> 
     285                                                        <xsl:call-template name="my:entity2"> 
    256286                                                                <xsl:with-param name="string" select="$nstr"/> 
    257287                                                        </xsl:call-template> 
     
    261291                                                <xsl:if test="contains($string, '&gt;')"> 
    262292                                                        <xsl:variable name="nstr"><xsl:value-of select="substring-before($string, '&gt;')"/><xsl:text>&amp;gt;</xsl:text><xsl:value-of select="substring-after($string, '&gt;')"/></xsl:variable> 
    263                                                         <xsl:call-template name="entity2"> 
     293                                                        <xsl:call-template name="my:entity2"> 
    264294                                                                <xsl:with-param name="string" select="$nstr"/> 
    265295                                                        </xsl:call-template>