home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / egrm2xegrm.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  6.6 KB  |  201 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <xsl:stylesheet version="1.0"
  18.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  19.                 xmlns:text="http://chaperon.sourceforge.net/schema/text/1.0"
  20.                 xmlns:st="http://chaperon.sourceforge.net/schema/syntaxtree/2.0"
  21.                 xmlns="http://chaperon.sourceforge.net/schema/grammar/2.0"
  22.                 exclude-result-prefixes="st text">
  23.  
  24.  <xsl:output indent="yes" method="xml" encoding="ASCII"/>
  25.  
  26.  <xsl:template match="st:output/st:grammar">
  27.   <grammar start="{st:start/st:name}">
  28.  
  29.    <xsl:if test="not (st:start)">
  30.     <xsl:message terminate="yes">
  31.      Start element is not defined!
  32.     </xsl:message>
  33.    </xsl:if>
  34.  
  35.    <xsl:comment>This file was generated! Don't edit!</xsl:comment>
  36.  
  37.    <xsl:apply-templates select="st:definition"/>
  38.   </grammar>
  39.  </xsl:template>
  40.  
  41.  <xsl:template match="st:definition">
  42.   <definition name="{st:name}">
  43.    <xsl:apply-templates select="st:regex"/>
  44.   </definition>
  45.  </xsl:template>
  46.  
  47.  <xsl:template match="st:regex">
  48.   <xsl:apply-templates select="st:choice|st:sequence|st:quantifier"/>
  49.  </xsl:template>
  50.  
  51.  <xsl:template match="st:element" >
  52.   <xsl:variable name="name" select="."/>
  53.   <xsl:choose>
  54.    <xsl:when test="/st:output/st:grammar/st:abbreviation[st:name=$name]">
  55.     <xsl:apply-templates select="/st:output/st:grammar/st:abbreviation[st:name=$name]/st:regex"/>
  56.    </xsl:when>
  57.    <xsl:otherwise>
  58.     <element name="{$name}"/>
  59.    </xsl:otherwise>
  60.   </xsl:choose>
  61.  </xsl:template>
  62.  
  63.  <xsl:template match="st:choice" >
  64.   <choice>
  65.    <xsl:apply-templates select="st:sequence|st:quantifier"/>
  66.   </choice>
  67.  </xsl:template>
  68.  
  69.  <xsl:template match="st:sequence">
  70.   <sequence>
  71.    <xsl:apply-templates select="st:quantifier"/>
  72.   </sequence>
  73.  </xsl:template>
  74.  
  75.  <xsl:template match="st:quantifier" >
  76.   <xsl:apply-templates select="st:optional|st:one-or-more|st:zero-or-more|st:term"/>
  77.  </xsl:template>
  78.  
  79.  <xsl:template match="st:optional" >
  80.   <optional>
  81.    <xsl:apply-templates select="st:term"/>
  82.   </optional>
  83.  </xsl:template>
  84.  
  85.  <xsl:template match="st:one-or-more">
  86.   <one-or-more>
  87.    <xsl:apply-templates select="st:term"/>
  88.   </one-or-more>
  89.  </xsl:template>
  90.  
  91.  <xsl:template match="st:zero-or-more">
  92.   <zero-or-more>
  93.    <xsl:apply-templates select="st:term"/>
  94.   </zero-or-more>
  95.  </xsl:template>
  96.  
  97. <!-- <xsl:template match="st:regexvar">
  98.   <xsl:choose>
  99.    <xsl:when test="count(st:regexmultiplicator/st:string)=2">
  100.     <concat>
  101.      <xsl:attribute name="minOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string[1])"/></xsl:attribute>
  102.      <xsl:attribute name="maxOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string[2])"/></xsl:attribute>
  103.      <xsl:apply-templates select="st:regexterm"/>
  104.     </concat>
  105.    </xsl:when>
  106.    <xsl:otherwise>
  107.     <concat>
  108.      <xsl:attribute name="minOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string)"/></xsl:attribute>
  109.      <xsl:attribute name="maxOccurs"><xsl:value-of select="normalize-space(st:regexmultiplicator/st:string)"/></xsl:attribute>
  110.      <xsl:apply-templates select="st:regexterm"/>
  111.     </concat>
  112.    </xsl:otherwise>
  113.   </xsl:choose>
  114.  </xsl:template>-->
  115.  
  116.  <xsl:template match="st:term">
  117.   <xsl:apply-templates select="st:class|st:nested|st:string|st:element|st:dot"/>
  118.  </xsl:template>
  119.  
  120.  <xsl:template match="st:nested">
  121.   <xsl:apply-templates select="st:choice|st:sequence|st:quantifier"/>
  122.  </xsl:template>
  123.  
  124.  <xsl:template match="st:dot">
  125.   <class exclusive="true">
  126.    <char value="#10"/>
  127.    <char value="#13"/>
  128.   </class>
  129.  </xsl:template>
  130.  
  131. <!-- <xsl:template match="st:regexabref">
  132.   <xsl:variable name="ref" select="translate(normalize-space(st:string), ' ', '')"/>
  133.   <xsl:apply-templates select="/st:output/st:grammar/st:token_decls/st:ab_decl[st:id=$ref]/st:output/st:regexexpression"/>
  134.  </xsl:template>-->
  135.  
  136.  <xsl:template match="st:string">
  137.   <xsl:choose>
  138.    <xsl:when test="count(st:char|st:masked-char)>1">
  139.   <sequence>
  140.    <xsl:apply-templates select="st:char|st:masked-char"/>
  141.   </sequence>
  142.    </xsl:when>
  143.    <xsl:otherwise>
  144.     <xsl:apply-templates select="st:char|st:masked-char"/>
  145.    </xsl:otherwise>
  146.   </xsl:choose>
  147.  </xsl:template>
  148.  
  149.  <xsl:template match="st:class">
  150.   <class>
  151.    <xsl:if test="st:exclusive">
  152.     <xsl:attribute name="exclusive">true</xsl:attribute>
  153.    </xsl:if>
  154.    <xsl:apply-templates select="st:interval|st:class-char|st:masked-char"/>
  155.   </class>
  156.  </xsl:template>
  157.  
  158.  <xsl:template match="st:class-char">
  159.   <char value="{.}"/>
  160.  </xsl:template>
  161.  
  162.  <xsl:template match="st:masked-char">
  163.   <char>
  164.    <xsl:choose>
  165.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'n'">
  166. <!--     <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>-->
  167.      <xsl:attribute name="value">#10</xsl:attribute>
  168.     </xsl:when>
  169.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'r'">
  170. <!--     <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>-->
  171.      <xsl:attribute name="value">#13</xsl:attribute>
  172.     </xsl:when>
  173.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 't'">
  174. <!--     <xsl:attribute name="content"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>-->
  175.      <xsl:attribute name="value">#9</xsl:attribute>
  176.     </xsl:when>
  177.     <xsl:when test="substring(translate(normalize-space(.), ' ', ''), 2,1) = 'u'">
  178.      <xsl:attribute name="value">#<xsl:value-of select="substring(translate(normalize-space(.), ' ', ''),3,6)"/></xsl:attribute>
  179.     </xsl:when>
  180.     <xsl:when test="contains(.,'\ ')">
  181.      <xsl:attribute name="value"><xsl:text disable-output-escaping="yes"> </xsl:text></xsl:attribute>
  182.     </xsl:when>
  183.     <xsl:otherwise>
  184.      <xsl:attribute name="value"><xsl:value-of select="substring(translate(normalize-space(.), ' ', ''), 2,1)"/></xsl:attribute>
  185.     </xsl:otherwise>
  186.    </xsl:choose>
  187.   </char>
  188.  </xsl:template>
  189.  
  190.  <xsl:template match="st:char">
  191.   <char value="{.}"/>
  192.  </xsl:template>
  193.  
  194.  <xsl:template match="st:interval">
  195.   <interval>
  196.    <xsl:apply-templates select="st:class-char|st:masked-char"/>
  197.   </interval>
  198.  </xsl:template>
  199.  
  200. </xsl:stylesheet>
  201.