1 <!-- Generate Java code to be inserted into HTMLSchema.java. --> 2 3 <!-- 4 // This file is part of TagSoup and is Copyright 2002-2008 by John Cowan. 5 // 6 // TagSoup is licensed under the Apache License, 7 // Version 2.0. You may obtain a copy of this license at 8 // http://www.apache.org/licenses/LICENSE-2.0 . You may also have 9 // additional legal rights not granted by this license. 10 // 11 // TagSoup is distributed in the hope that it will be useful, but 12 // unless required by applicable law or agreed to in writing, TagSoup 13 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 14 // OF ANY KIND, either express or implied; not even the implied warranty 15 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 --> 17 18 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 19 xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl" 20 version="1.0"> 21 22 <xsl:output method="text"/> 23 24 <xsl:strip-space elements="*"/> 25 26 <!-- The main template. This generates calls on the Schema routines 27 setURI(), setPrefix(), elementType(), parent(), attribute(), 28 and entity() in that order. Several special cases are 29 handled by template calls. --> 30 <xsl:template match="tssl:schema"> 31 <!-- setURI() --> 32 <xsl:text>		setURI("</xsl:text> 33 <xsl:value-of select="@ns"/> 34 <xsl:text>");
</xsl:text> 35 <!-- setPrefix() --> 36 <xsl:text>		setPrefix("</xsl:text> 37 <xsl:value-of select="@prefix"/> 38 <xsl:text>");
</xsl:text> 39 <!-- elementType() special cases --> 40 <xsl:text>		elementType("<pcdata>", M_EMPTY, M_PCDATA, 0);
</xsl:text> 41 <xsl:text>		elementType("<root>", </xsl:text> 42 <xsl:apply-templates select="tssl:element/tssl:isRoot"/> 43 <xsl:text>, M_EMPTY, 0);
</xsl:text> 44 <!-- elementType() main loop --> 45 <xsl:apply-templates select="//tssl:element"> 46 <xsl:sort select="@name"/> 47 </xsl:apply-templates> 48 <!-- parent() special cases --> 49 <xsl:call-template name="parent"> 50 <xsl:with-param name="elem" select="'<pcdata>'"/> 51 <xsl:with-param name="parent" select="//tssl:element[@text-parent='true']/@name"/> 52 </xsl:call-template> 53 <xsl:call-template name="parent"> 54 <xsl:with-param name="elem" select="tssl:element/@name"/> 55 <xsl:with-param name="parent" select="'<root>'"/> 56 </xsl:call-template> 57 <!-- parent() main loop --> 58 <xsl:apply-templates select="//tssl:element/tssl:element" mode="parent"> 59 <xsl:sort select="@name"/> 60 </xsl:apply-templates> 61 <xsl:apply-templates select="//tssl:element/tssl:attribute"> 62 <xsl:sort select="../@name"/> 63 <xsl:sort select="@name"/> 64 </xsl:apply-templates> 65 <!-- attribute() main loop --> 66 <xsl:apply-templates select="tssl:attribute"> 67 <xsl:sort select="@name"/> 68 </xsl:apply-templates> 69 <!-- entity() main loop --> 70 <xsl:apply-templates select="tssl:entity"> 71 <xsl:sort select="@name"/> 72 </xsl:apply-templates> 73 </xsl:template> 74 75 <!-- Generates a single call to elementType(). --> 76 <xsl:template match="tssl:element"> 77 <xsl:text>		elementType("</xsl:text> 78 <xsl:value-of select="@name"/> 79 <xsl:text>", </xsl:text> 80 <xsl:choose> 81 <xsl:when test="@type = 'element'"> 82 <xsl:apply-templates select="tssl:contains"/> 83 </xsl:when> 84 <xsl:when test="@type = 'string'"> 85 <xsl:text>M_PCDATA</xsl:text> 86 </xsl:when> 87 <xsl:when test="@type = 'mixed'"> 88 <xsl:text>M_PCDATA|</xsl:text> 89 <xsl:apply-templates select="tssl:contains"/> 90 </xsl:when> 91 <xsl:when test="@type = 'empty'"> 92 <xsl:text>M_EMPTY</xsl:text> 93 </xsl:when> 94 <xsl:when test="@type = 'any'"> 95 <xsl:text>M_ANY</xsl:text> 96 </xsl:when> 97 <xsl:when test="@type = 'cdata'"> 98 <xsl:text>M_PCDATA</xsl:text> 99 </xsl:when> 100 </xsl:choose> 101 <xsl:text>, </xsl:text> 102 <xsl:apply-templates select="tssl:memberOf"/> 103 <xsl:apply-templates select="tssl:memberOfAny"/> 104 <xsl:apply-templates select="tssl:isRoot"/> 105 <xsl:text>, </xsl:text> 106 <xsl:choose> 107 <xsl:when test="@type = 'cdata'"> 108 <xsl:text>F_CDATA</xsl:text> 109 </xsl:when> 110 <xsl:when test="@closeMode = 'restartable'"> 111 <xsl:text>F_RESTART</xsl:text> 112 </xsl:when> 113 <xsl:when test="@closeMode = 'unclosable'"> 114 <xsl:text>F_NOFORCE</xsl:text> 115 </xsl:when> 116 <xsl:otherwise> 117 <xsl:text>0</xsl:text> 118 </xsl:otherwise> 119 </xsl:choose> 120 <xsl:text>);
</xsl:text> 121 </xsl:template> 122 123 <!-- Applied from tssl:element to generate the contains argument. --> 124 <xsl:template match="tssl:contains"> 125 <xsl:value-of select="@group"/> 126 <xsl:if test="position() != last()"> 127 <xsl:text>|</xsl:text> 128 </xsl:if> 129 </xsl:template> 130 131 <!-- Applied from tssl:element to generate the memberOf argument. --> 132 <xsl:template match="tssl:memberOf"> 133 <xsl:value-of select="@group"/> 134 <xsl:if test="position() != last()"> 135 <xsl:text>|</xsl:text> 136 </xsl:if> 137 </xsl:template> 138 139 <!-- Applied from tssl:element to handle memberOfAny. --> 140 <xsl:template match="tssl:memberOfAny"> 141 <xsl:text>M_ANY & ~M_ROOT</xsl:text> 142 </xsl:template> 143 144 <!-- Applied from tssl:element to handle isRoot. --> 145 <xsl:template match="tssl:isRoot"> 146 <xsl:text>M_ROOT</xsl:text> 147 </xsl:template> 148 149 <!-- Generates a single call to parent(). The mode is used to prevent XSLT 150 from getting confused and generating elementType calls instead. --> 151 <xsl:template match="tssl:element/tssl:element" name="parent" mode="parent"> 152 <xsl:param name="elem" select="@name"/> 153 <xsl:param name="parent" select="../@name"/> 154 <xsl:text>		parent("</xsl:text> 155 <xsl:value-of select="$elem"/> 156 <xsl:text>", "</xsl:text> 157 <xsl:value-of select="$parent"/> 158 <xsl:text>");
</xsl:text> 159 </xsl:template> 160 161 <!-- Generates a single call to attribute(). --> 162 <xsl:template match="tssl:element/tssl:attribute" name="tssl:attribute"> 163 <xsl:param name="elem" select="../@name"/> 164 <xsl:param name="attr" select="@name"/> 165 <xsl:param name="type" select="@type"/> 166 <xsl:param name="default" select="@default"/> 167 <xsl:text>		attribute("</xsl:text> 168 <xsl:value-of select="$elem"/> 169 <xsl:text>", "</xsl:text> 170 <xsl:value-of select="$attr"/> 171 <xsl:text>", "</xsl:text> 172 <xsl:choose> 173 <xsl:when test="$type"> 174 <xsl:value-of select="$type"/> 175 </xsl:when> 176 <xsl:when test="not($type)"> 177 <xsl:text>CDATA</xsl:text> 178 </xsl:when> 179 </xsl:choose> 180 <xsl:text>", </xsl:text> 181 <xsl:choose> 182 <xsl:when test="$default"> 183 <xsl:text>"</xsl:text> 184 <xsl:value-of select="$default"/> 185 <xsl:text>"</xsl:text> 186 </xsl:when> 187 <xsl:when test="not($default)"> 188 <xsl:text>null</xsl:text> 189 </xsl:when> 190 </xsl:choose> 191 <xsl:text>);
</xsl:text> 192 </xsl:template> 193 194 <!-- Generates calls to attribute() (using the above template) 195 based on the global attribute definitions. --> 196 <xsl:template match="tssl:schema/tssl:attribute"> 197 <xsl:variable name="attr" select="@name"/> 198 <xsl:variable name="type" select="@type"/> 199 <xsl:variable name="default" select="@default"/> 200 <xsl:for-each select="//tssl:element"> 201 <xsl:sort select="@name"/> 202 <xsl:call-template name="tssl:attribute"> 203 <xsl:with-param name="elem" select="@name"/> 204 <xsl:with-param name="attr" select="$attr"/> 205 <xsl:with-param name="type" select="$type"/> 206 <xsl:with-param name="default" select="$default"/> 207 </xsl:call-template> 208 </xsl:for-each> 209 </xsl:template> 210 211 <!-- Generates a single call to entity(). --> 212 <xsl:template match="tssl:entity"> 213 <xsl:text>		entity("</xsl:text> 214 <xsl:value-of select="@name"/> 215 <xsl:text>", 0x</xsl:text> 216 <xsl:value-of select="@codepoint"/> 217 <xsl:text>);
</xsl:text> 218 </xsl:template> 219 220 </xsl:transform> 221