File: structure-html.xsl

package info (click to toggle)
cocoon 1.8-1
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 12,016 kB
  • ctags: 3,793
  • sloc: xml: 16,682; java: 8,089; sh: 174; makefile: 61
file content (82 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

 <xsl:template match="/">
  <xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction>

  <html>
   <head>
    <title>XML Structure</title>
    <style type="text/css"><xsl:comment>
        #main {
                border: none;
                font-size: 10px;
                line-height: 10px;
                font-family: sans-serif
                font-variant: normal;
                font-style: normal;
                font-stretch: normal;
                font-size-adjust: none
                padding: 0.5em 0.5em 0.5em 0.5em
        }
        
        IMG {
                padding: 0px 0px 0px 0px;
                margin: 0px 0px 0px 0px;
        }
       
        .level1 { color: black}
        .level2 { color: red }
        .level3 { color: green }
        .level4 { color: blue }
   </xsl:comment></style>
   </head>
   <body>
    <xsl:apply-templates/>
   </body>
  </html>
 </xsl:template>

 <xsl:template match="*">
  <xsl:variable name="level"><xsl:value-of select="count(ancestor-or-self::*)"/></xsl:variable>

  <xsl:choose>
   <xsl:when test="$level=1">
    <img src="images/root.gif"/>
   </xsl:when>

   <xsl:when test="$level!=1">
    <xsl:for-each select="ancestor::*">
     <xsl:choose>
      <xsl:when test="(count(ancestor::*)=0) or (count(following-sibling::*)=0)">
       <img src="images/space.gif" height="1" width="18"/>
      </xsl:when>
      <xsl:otherwise>
       <img src="images/branch.gif"/>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:for-each>

    <xsl:choose>
     <xsl:when test="count(following-sibling::*)!=0">
      <img src="images/tree.gif"/>
     </xsl:when>
     <xsl:otherwise>
      <img src="images/leaf.gif"/>
     </xsl:otherwise>
    </xsl:choose>

   </xsl:when>
  </xsl:choose>

  <span class="level{$level}">
   <xsl:value-of select="name(.)"/>
  </span>
  <br/>
  <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="@*|comment()|processing-instruction()|text()"/>

</xsl:stylesheet>