File:  [LON-CAPA] / modules / damieng / schema_documentation / XMLSchema.xsl
Revision 1.1: download - view: text, annotated - select for diffs
Thu Jan 5 19:37:43 2017 UTC (7 years, 4 months ago) by damieng
Branches: MAIN
CVS tags: HEAD
added a Perl script to generate the HTML documentation from the schema (the XSLT comes from Jaxe)

    1: <?xml version="1.0" encoding='UTF-8' ?>
    2: 
    3: <xsl:stylesheet version="1.0"
    4:                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
    5:                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    6:                 exclude-result-prefixes="xs">
    7:   
    8:   <xsl:output method="html" indent="yes"
    9:               doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
   10: 
   11:     <xsl:param name="jaxe-uri-xsl"/>
   12:     <xsl:variable name="uri-xsl"><xsl:call-template name="rep-uri"><xsl:with-param name="chemin" select="$jaxe-uri-xsl"/></xsl:call-template></xsl:variable>
   13:     <xsl:variable name="langue"><xsl:choose>
   14:         <xsl:when test="/xs:schema/@xml:lang"><xsl:value-of select="translate(/xs:schema/@xml:lang, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/></xsl:when>
   15:         <xsl:otherwise>fr</xsl:otherwise>
   16:     </xsl:choose></xsl:variable>
   17:     <xsl:variable name="messages" select="document(concat($uri-xsl, '/XMLSchema_messages_', $langue, '.xml'))/messages"/>
   18:     
   19:   <xsl:template match="xs:schema">
   20:     <html>
   21:       <head>
   22:         <title><xsl:value-of select="$messages/message[@label='Schéma XML']"/></title>
   23:         <style type="text/css">
   24: body { color: #000000; background: #FFFFFF }
   25: .documentation { font-family: monospace; color: #005500; white-space: pre-line }
   26: .grandlien { font-size: 120%; font-weight: bold }
   27: .nomtitre { color: #550000 }
   28: .nomattribut { color: #000055; font-weight: bold }
   29: .indentation { margin-left: 2em; margin-top: 1em; margin-bottom: 1em }
   30:         </style>
   31:       </head>
   32:       <body>
   33:         <div align="center">
   34:         <h1><xsl:value-of select="$messages/message[@label='Schéma XML']"/></h1>
   35:         </div>
   36:         <br/>
   37:         <span class="grandlien">
   38:         <a href="#index"><xsl:value-of select="$messages/message[@label='Aller à l index']"/></a><br/>
   39:         </span>
   40:         <hr/>
   41:         <xsl:apply-templates/>
   42:         <br/>
   43:         <a name="index"/>
   44:         <h3><xsl:value-of select="$messages/message[@label='Index']"/></h3>
   45:         <xsl:for-each select="//*[local-name()!='attribute' and @name!='']">
   46:           <xsl:sort select="@name"/>
   47:           <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
   48:           <xsl:variable name="total" select="count(//*[@name=current()/@name])"/>
   49:           <a href="#{@name}_{$numero}"><xsl:value-of select="@name"/></a>
   50:           <xsl:if test="$total &gt; 1 and ancestor::*[@name!=''][1]">
   51:             (<xsl:value-of select="$messages/message[@label='sous']"/><xsl:text> </xsl:text><xsl:value-of select="ancestor::*[@name!=''][1]/@name"/>)
   52:           </xsl:if>
   53:           <br/>
   54:         </xsl:for-each>
   55:       </body>
   56:     </html>
   57:   </xsl:template>
   58:   
   59:   <xsl:template match="xs:element">
   60:     <xsl:choose>
   61:     <xsl:when test="@ref">
   62:       <xsl:variable name="localref">
   63:         <xsl:choose>
   64:           <xsl:when test="contains(@ref,':')">
   65:             <xsl:value-of select="substring-after(@ref,':')"/>
   66:           </xsl:when>
   67:           <xsl:otherwise>
   68:             <xsl:value-of select="@ref"/>
   69:           </xsl:otherwise>
   70:         </xsl:choose>
   71:       </xsl:variable>
   72:       <xsl:variable name="numero">
   73:         <xsl:for-each select="/xs:schema/xs:element[@name=$localref][1]">
   74:           <xsl:value-of select="count(preceding::*[@name=current()/@name])"/>
   75:         </xsl:for-each>
   76:       </xsl:variable>
   77:       <a href="#{$localref}_{$numero}"><xsl:value-of select="@ref"/></a>
   78:       <br/>
   79:     </xsl:when>
   80:     <xsl:otherwise>
   81:       <xsl:variable name="numero"><xsl:value-of select="count(preceding::*[@name=current()/@name])"/></xsl:variable>
   82:       <a name="{@name}_{$numero}"/>
   83:       <h3><xsl:value-of select="$messages/message[@label='Elément']"/><xsl:text> </xsl:text><span class="nomtitre"><xsl:value-of select="@name"/></span></h3>
   84:       <xsl:if test="@type">
   85:         <xsl:value-of select="$messages/message[@label='type:']"/><xsl:text> </xsl:text><xsl:call-template name="nomtype"/><br/>
   86:       </xsl:if>
   87:       <xsl:apply-templates/>
   88:       <br/>
   89:       <xsl:if test="parent::xs:schema">
   90:         <xsl:for-each select="//xs:element[.//xs:element[@ref=current()/@name or substring-after(@ref,':')=current()/@name]] | //xs:group[.//xs:element[@ref=current()/@name or substring-after(@ref,':')=current()/@name]]">
   91:           <xsl:if test="position() = 1">
   92:             <xsl:value-of select="$messages/message[@label='Parents:']"/>
   93:           </xsl:if>
   94:           <xsl:if test="position() != 1">, </xsl:if>
   95:           <xsl:variable name="numero2"><xsl:value-of select="count(preceding::*[@name=current()/@name])"/></xsl:variable>
   96:           <a href="#{@name}_{$numero2}"><xsl:value-of select="@name"/></a> 
   97:         </xsl:for-each>
   98:         <br/>
   99:       </xsl:if>
  100:       <xsl:if test="not(ancestor::xs:choice or ancestor::xs:sequence)">
  101:         <hr/>
  102:       </xsl:if>
  103:     </xsl:otherwise>
  104:     </xsl:choose>
  105:   </xsl:template>
  106: 
  107:   <xsl:template match="xs:group">
  108:     <xsl:choose>
  109:     <xsl:when test="@ref">
  110:       <xsl:variable name="localref">
  111:         <xsl:choose>
  112:           <xsl:when test="contains(@ref,':')">
  113:             <xsl:value-of select="substring-after(@ref,':')"/>
  114:           </xsl:when>
  115:           <xsl:otherwise>
  116:             <xsl:value-of select="@ref"/>
  117:           </xsl:otherwise>
  118:         </xsl:choose>
  119:       </xsl:variable>
  120:       <xsl:variable name="numero">
  121:         <xsl:for-each select="/xs:schema/xs:group[@name=$localref][1]">
  122:           <xsl:value-of select="count(preceding::*[@name=current()/@name])"/>
  123:         </xsl:for-each>
  124:       </xsl:variable>
  125:       <a href="#{$localref}_{$numero}"><xsl:value-of select="@ref"/></a>
  126:       <br/>
  127:     </xsl:when>
  128:     <xsl:otherwise>
  129:       <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
  130:       <a name="{@name}_{$numero}"/>
  131:       <h3><xsl:value-of select="$messages/message[@label='Groupe']"/><xsl:text> </xsl:text><span class="nomtitre"><xsl:value-of select="@name"/></span></h3>
  132:       <xsl:apply-templates/>
  133:       <br/>
  134:       <xsl:for-each select="//xs:element[.//xs:group[@ref=current()/@name or substring-after(@ref,':')=current()/@name]] | //xs:group[.//xs:group[@ref=current()/@name or substring-after(@ref,':')=current()/@name]]">
  135:         <xsl:if test="position() = 1">
  136:           <xsl:value-of select="$messages/message[@label='Parents:']"/>
  137:         </xsl:if>
  138:         <xsl:if test="position() != 1">, </xsl:if>
  139:         <xsl:variable name="numero2"><xsl:value-of select="count(preceding::*[@name=current()/@name])"/></xsl:variable>
  140:         <a href="#{@name}_{$numero2}"><xsl:value-of select="@name"/></a> 
  141:       </xsl:for-each>
  142:       <br/>
  143:       <hr/>
  144:     </xsl:otherwise>
  145:     </xsl:choose>
  146:   </xsl:template>
  147: 
  148:   <xsl:template match="xs:documentation">
  149:     <div class="documentation"><xsl:value-of select="."/></div>
  150:     <br/>
  151:   </xsl:template>
  152:   
  153:   <xsl:template match="xs:choice">
  154:     <xsl:value-of select="$messages/message[@label='Choix parmi:']"/>
  155:     <ul>
  156:       <xsl:for-each select="*">
  157:         <li><xsl:apply-templates select="."/></li>
  158:       </xsl:for-each>
  159:     </ul>
  160:   </xsl:template>
  161:   
  162:   <xsl:template match="xs:sequence">
  163:     <xsl:value-of select="$messages/message[@label='Séquence parmi:']"/>
  164:     <ul>
  165:       <xsl:for-each select="*">
  166:         <li><xsl:apply-templates select="."/></li>
  167:       </xsl:for-each>
  168:     </ul>
  169:   </xsl:template>
  170:   
  171:   <xsl:template match="xs:complexType">
  172:     <!--Type complexe-->
  173:     <xsl:if test="@name">
  174:       <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
  175:       <a name="{@name}_{$numero}"/>
  176:       <h3><xsl:value-of select="$messages/message[@label='Type complexe']"/><xsl:text> </xsl:text><span class="nomtitre"><xsl:value-of select="@name"/></span></h3>
  177:     </xsl:if>
  178:     <xsl:if test="@ref">
  179:       <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
  180:       <a href="{@ref}_{$numero}"><xsl:value-of select="@ref"/></a><br/>
  181:     </xsl:if>
  182:     <xsl:if test="@mixed='true'">
  183:       <xsl:value-of select="$messages/message[@label='Peut contenir du texte']"/><br/>
  184:     </xsl:if>
  185:     <div class="indentation">
  186:       <xsl:apply-templates/>
  187:     </div>
  188:     <xsl:if test="@name">
  189:       <hr/>
  190:     </xsl:if>
  191:   </xsl:template>
  192:   
  193:   <xsl:template match="xs:attribute">
  194:     <xsl:value-of select="$messages/message[@label='Attribut']"/><xsl:text> </xsl:text><span class="nomattribut"><xsl:value-of select="@name"/></span>:
  195:     <div class="indentation">
  196:     <xsl:choose>
  197:     <xsl:when test="@use='required'">
  198:       <xsl:value-of select="$messages/message[@label='obligatoire']"/><br/>
  199:     </xsl:when>
  200:     <xsl:otherwise>
  201:       <xsl:value-of select="$messages/message[@label='facultatif']"/><br/>
  202:     </xsl:otherwise>
  203:     </xsl:choose>
  204:     <xsl:if test="@type">
  205:       <xsl:value-of select="$messages/message[@label='type:']"/><xsl:text> </xsl:text><xsl:call-template name="nomtype"/><br/>
  206:     </xsl:if>
  207:     <xsl:apply-templates/>
  208:     </div>
  209:   </xsl:template>
  210:   
  211:   <xsl:template match="xs:simpleType">
  212:     <xsl:choose>
  213:       <xsl:when test="@name!=''">
  214:         <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
  215:         <a name="{@name}_{$numero}"/>
  216:         <h3><xsl:value-of select="$messages/message[@label='Type simple']"/><xsl:text> </xsl:text><span class="nomtitre"><xsl:value-of select="@name"/></span></h3>
  217:         <xsl:apply-templates/>
  218:         <hr/>
  219:       </xsl:when>
  220:       <xsl:otherwise>
  221:         <xsl:apply-templates/>
  222:       </xsl:otherwise>
  223:     </xsl:choose>
  224:   </xsl:template>
  225:   
  226:   <xsl:template match="xs:restriction">
  227:     <xsl:value-of select="$messages/message[@label='Restriction des valeurs']"/>
  228:     <xsl:if test="@base!=''">
  229:       <xsl:text> </xsl:text>
  230:       <xsl:value-of select="$messages/message[@label='basée sur']"/>
  231:       <xsl:text> </xsl:text>
  232:       <xsl:value-of select="@base"/>
  233:     </xsl:if>
  234:     <xsl:if test="*">
  235:       <ul>
  236:         <xsl:apply-templates/>
  237:       </ul>
  238:     </xsl:if>
  239:   </xsl:template>
  240:   
  241:   <xsl:template match="xs:enumeration">
  242:     <li><tt><xsl:value-of select="@value"/></tt></li>
  243:   </xsl:template>
  244:   
  245:   <xsl:template match="xs:pattern">
  246:     <li><tt><xsl:value-of select="@value"/></tt></li>
  247:   </xsl:template>
  248:   
  249:   <xsl:template match="xs:minInclusive">
  250:     <li><tt>&gt;= <xsl:value-of select="@value"/></tt></li>
  251:   </xsl:template>
  252:   
  253:   <xsl:template match="xs:minExclusive">
  254:     <li><tt>&gt; <xsl:value-of select="@value"/></tt></li>
  255:   </xsl:template>
  256:   
  257:   <xsl:template match="xs:maxInclusive">
  258:     <li><tt>&lt;= <xsl:value-of select="@value"/></tt></li>
  259:   </xsl:template>
  260:   
  261:   <xsl:template match="xs:maxExclusive">
  262:     <li><tt>&lt; <xsl:value-of select="@value"/></tt></li>
  263:   </xsl:template>
  264:   
  265:   <xsl:template match="xs:attributeGroup">
  266:     <xsl:choose>
  267:     <xsl:when test="@ref">
  268:       <xsl:variable name="localref">
  269:         <xsl:choose>
  270:           <xsl:when test="contains(@ref,':')">
  271:             <xsl:value-of select="substring-after(@ref,':')"/>
  272:           </xsl:when>
  273:           <xsl:otherwise>
  274:             <xsl:value-of select="@ref"/>
  275:           </xsl:otherwise>
  276:         </xsl:choose>
  277:       </xsl:variable>
  278:       <xsl:variable name="numero">
  279:         <xsl:for-each select="/xs:schema/xs:attributeGroup[@name=$localref][1]">
  280:           <xsl:value-of select="count(preceding::*[@name=current()/@name])"/>
  281:         </xsl:for-each>
  282:       </xsl:variable>
  283:       <a href="#{$localref}_{$numero}"><xsl:value-of select="@ref"/></a>
  284:       <br/>
  285:       <br/>
  286:     </xsl:when>
  287:     <xsl:otherwise>
  288:       <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
  289:       <a name="{@name}_{$numero}"/>
  290:       <h3><xsl:value-of select="$messages/message[@label='Groupe d attributs:']"/><xsl:text> </xsl:text><span class="nomtitre"><xsl:value-of select="@name"/></span></h3>
  291:       <xsl:apply-templates/>
  292:       <br/>
  293:       <xsl:for-each select="//xs:element[.//xs:attributeGroup[@ref=current()/@name or substring-after(@ref,':')=current()/@name]] | //xs:attributeGroup[.//xs:attributeGroup[@ref=current()/@name or substring-after(@ref,':')=current()/@name]] | //xs:complexType[.//xs:attributeGroup[@ref=current()/@name or substring-after(@ref,':')=current()/@name] and @name]">
  294:         <xsl:if test="position() = 1">
  295:           <xsl:value-of select="$messages/message[@label='Parents:']"/>
  296:         </xsl:if>
  297:         <xsl:if test="position() != 1">, </xsl:if>
  298:         <xsl:variable name="numero2"><xsl:value-of select="count(preceding::*[@name=current()/@name])"/></xsl:variable>
  299:         <a href="#{@name}_{$numero2}"><xsl:value-of select="@name"/></a> 
  300:       </xsl:for-each>
  301:       <br/>
  302:       <hr/>
  303:     </xsl:otherwise>
  304:     </xsl:choose>
  305:   </xsl:template>
  306: 
  307:   <xsl:template name="nomtype">
  308:     <xsl:variable name="localType">
  309:       <xsl:choose>
  310:         <xsl:when test="contains(@type,':')">
  311:           <xsl:value-of select="substring-after(@type,':')"/>
  312:         </xsl:when>
  313:         <xsl:otherwise>
  314:           <xsl:value-of select="@type"/>
  315:         </xsl:otherwise>
  316:       </xsl:choose>
  317:     </xsl:variable>
  318:     <xsl:choose>
  319:         <xsl:when test="/xs:schema/xs:simpleType[@name=$localType]|/xs:schema/xs:complexType[@name=$localType]">
  320:           <xsl:for-each select="/xs:schema/xs:simpleType[@name=$localType]|/xs:schema/xs:complexType[@name=$localType]">
  321:             <xsl:variable name="numero" select="count(preceding::*[@name=current()/@name])"/>
  322:             <a href="#{@name}_{$numero}"><xsl:value-of select="@name"/></a>
  323:           </xsl:for-each>
  324:         </xsl:when>
  325:         <xsl:otherwise>
  326:           <tt><xsl:value-of select="@type"/></tt>
  327:         </xsl:otherwise>
  328:     </xsl:choose>
  329:   </xsl:template>
  330:   
  331:     <xsl:template name="rep-uri">
  332:         <!-- renvoit le chemin du répertoire d'un fichier à partir de l'URI complète, sous forme d'URI  -->
  333:         <xsl:param name="chemin"/>
  334:         <!-- séparateur de chemins ( normalement / mais parfois \ avec file:// sur Windows ? ) -->
  335:         <xsl:variable name="sepuri"><xsl:choose>
  336:             <xsl:when test="contains($chemin, '\')">\</xsl:when>
  337:             <xsl:otherwise>/</xsl:otherwise>
  338:         </xsl:choose></xsl:variable>
  339:         <xsl:choose>
  340:             <xsl:when test="contains($chemin,$sepuri) and contains(substring-after($chemin,$sepuri),$sepuri)">
  341:                 <xsl:value-of select="substring-before($chemin,$sepuri)"/><xsl:value-of select="$sepuri"/><xsl:call-template name="rep-uri"><xsl:with-param name="chemin" select="substring-after($chemin,$sepuri)"/></xsl:call-template>
  342:             </xsl:when>
  343:             <xsl:otherwise>
  344:                 <xsl:value-of select="substring-before($chemin,$sepuri)"/>
  345:             </xsl:otherwise>
  346:         </xsl:choose>
  347:     </xsl:template>
  348:     
  349: </xsl:stylesheet>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>