DIAGRAM Center

  • Increase font size
  • Default font size
  • Decrease font size
Research

XSL Transform for Content Model

This XSL transform converts Content Model XML to formatted HTML.  The file can be found at http://diagramcenter.org/examples/desc2html.xsl.

   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 
  83 
  84 
  85 
  86 
  87 
  88 
  89 
  90 
  91 
  92 
  93 
  94 
  95 
  96 
  97 




  98 


  99 


 100 
 101 
 102 
 103 
 104 
 105 
 106 
 107 

 108 
 109 
 110 
 111 
 112 

 113 

 114 
 115 

 116 
 117 
 118 
 119 
 120 
 121 
 122 


 123 

 124 
 125 
 126 
 127 
 128 
 129 
 130 
 131 
 132 
 133 
 134 
 135 
 136 
 137 
 138 
 139 
 140 
 141 
 142 

 143 
 144 
 145 
 146 
 147 
 148 
 149 
 150 
 151 
 152 
 153 
 154 
 155 
 156 
 157 
 158 
 159 
 160 
 161 
 162 
 163 
 164 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    xmlns:zai="http://www.daisy.org/ns/z3998/authoring/"
    xmlns:d="http://www.daisy.org/ns/z3998/authoring/features/description/"
    xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xd" 
      version="1.0">
    
    <xsl:template match="/" priority="1">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <style type="text/css">
                    body {
                        font-family : arial, sans-serif;
                        font-size : 1em
                    }
                    h1 {
                        font-size: 1.2em;
                    }
                    h2 {
                        font-size: 1.1em;
                        color: rgb(0,0,110)
                    }
                    h2.about {
                        font-size: 1em;
                        color: rgb(0,0,0)
                    }
                    div.container {
                        border-top: solid 1px rgb(0,0,255);
                        width: 80%;
                        padding: 5px;
                        margin-bottom: 10px;
                        background-color: rgb(255,255,255)
                    }
                    div.about, div.access {
                        font-size: 0.9em
                    }
                    div.annotation {
                        font-size: 0.8em;
                        font-weight: bold;
                        width: 60%;
                        border-top: 1px solid rgb(0,0,0)
                    }
                    p.anno-hd {
                        color: rgb(0,0,110)
                    }
                    img {
                        color: rgb(0,0,255)
                    }
                    ul {
                        list-style-type: none
                    }
                    .center {
                        text-align: center
                    }
                </style>
            </head>
            <body>
                <h1>DIAGRAM Description</h1>
                
                <xsl:for-each select="//d:description">
                    <xsl:apply-templates select="."/>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="d:description">
        <xsl:call-template name="about-this-description">
            <xsl:with-param name="meta" select="child::d:head"/>
        </xsl:call-template>
        
        <xsl:apply-templates select="child::d:body"/>
        
        <xsl:if test="//zai:meta[@property='dc:accessRights']">
            <xsl:element name="div">
                <xsl:attribute name="class">access center</xsl:attribute>
                <xsl:element name="div">
                    <xsl:value-of 
                      select="//zai:meta[@property='dc:accessRights']"/>
                </xsl:element>
            </xsl:element>
        </xsl:if>
    </xsl:template>

    <xsl:template name="about-this-description">
        <xsl:param name="meta"/>
        
        <xsl:element name="div">
            <xsl:attribute name="class">container about</xsl:attribute>
            
            <xsl:element name="h2">
                <xsl:attribute name="class">about</xsl:attribute>
                <xsl:text>About this description</xsl:text>
            </xsl:element>
            
            <ul>
                <li><strong>Author:</strong>&#160;&#160;<xsl:value-of 
                  select="$meta/zai:meta[@property='dc:creator'][1]"/>, <xsl
                  :value-of 
                  select="$meta/zai:meta[@property='diagram:credentials'][1]"/>
                  </li>
                <li><strong>Target Age:</strong> &#160;&#160;<xsl:value-of selec
                  t="$meta/zai:meta[@property='diagram:targetAge']/@content"/>
                  </li>
                <li><strong>Target Grade:</strong>&#160;&#160;<xsl:value-of sele
                  ct="$meta/zai:meta[@property='diagram:targetGrade']/@content"/
                  ></li>
            </ul>
        </xsl:element>
    </xsl:template>

    <xsl:template match="*[parent::d:body][not(self::zai:annotation)]">
        <xsl:variable name="ename" select="local-name(.)"/>
        <xsl:element name="div">
            <xsl:attribute name="id"><xsl:value-of select="@xml:id"/><
              /xsl:attribute>
            <xsl:attribute name="class">container</xsl:attribute>
            <xsl:element name="h2">
                <xsl:choose>
                    <xsl:when test="$ename='summary'">Summary</xsl:when>
                    <xsl:when test="$ename='longdesc'">Long Description<
                      /xsl:when>
                    <xsl:when test="$ename='simplifiedLanguageDescription'">
                      Simplified Language Description</xsl:when>
                    <xsl:when test="$ename='tactile'">Tactile Image</xsl:when>
                    <xsl:when test="$ename='simplifiedImage'">Simplified Image<
                      /xsl:when>
                </xsl:choose>
            </xsl:element>
            <xsl:apply-templates/>
            <xsl:if test="//zai:annotation[@ref=current()/@xml:id]">
                <xsl:element name="div">
                    <xsl:attribute name="class">annotation</xsl:attribute>
                    <p class="anno-hd">Annotation added by <xsl:value-of 
                      select="//zai:annotation[@ref=current()/@xml:id]/@by"/>:
                      </p>
                    <xsl:apply-templates 
                      select="//zai:annotation[@ref=current()/@xml:id][1]/*"/>
                </xsl:element>
            </xsl:if>
        </xsl:element>
    </xsl:template>

    <xsl:template match="zai:p">
        <xsl:element name="p">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="zai:object">
        <xsl:element name="img">
            <xsl:attribute name="src">
                <xsl:value-of select="@src"/>
            </xsl:attribute>
            <xsl:attribute name="srctype">
                <xsl:choose>
                    <xsl:when test="contains(@src, '.svg')">image/svg+xml<
                      /xsl:when>
                    <xsl:otherwise>unknown</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <xsl:attribute name="alt">
            <xsl:choose>
                <xsl:when test="parent::d:tactile">[Tactile image]</xsl:when>
                <xsl:otherwise>[Simplified image]</xsl:otherwise>
            </xsl:choose>
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="zai:annotation[parent::d:body]"/>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

 

You are here: Research DTB Hardware