1 <?xml version="1.0"?> 2 <!-- 3 Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 --> 19 <xsl:stylesheet version="1.0" 20 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 21 xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" 22 xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 23 24 <xsl:output indent="yes"/> 25 <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> 26 27 28 29 <!-- Match the document itself. --> 30 31 <xsl:template match="/"> 32 <axsl:stylesheet version="1.0"> 33 34 <axsl:output indent="yes"/> 35 <!-- NOTE: Hard-coded doctypes to hopefully satisfy JavaScript code. --> 36 <!-- doctype-public="-//W3C//DTD XHTML 1.1//EN" 37 doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" --> 38 39 <axsl:template match="/"> 40 41 <!-- Include the remaining attributes. --> 42 <xsl:apply-templates select="@*"/> 43 44 <!-- Process the elements. --> 45 <xsl:apply-templates select="*"/> 46 47 </axsl:template> 48 </axsl:stylesheet> 49 </xsl:template> 50 51 52 53 <!-- Match special conditional expression attributes. --> 54 55 <xsl:template match="*[@template:if]"> 56 <axsl:if test="{@template:if}"> 57 <xsl:choose> 58 <xsl:when test="@template:element"> 59 <xsl:call-template name="enter-element"> 60 <xsl:with-param name="other-elements" select="@template:element"/> 61 </xsl:call-template> 62 </xsl:when> 63 <xsl:otherwise> 64 <xsl:call-template name="enter-attribute"/> 65 </xsl:otherwise> 66 </xsl:choose> 67 </axsl:if> 68 </xsl:template> 69 70 71 72 <!-- Match element references. --> 73 74 <xsl:template match="*[not(@template:if) and @template:element]"> 75 <xsl:call-template name="enter-element"> 76 <xsl:with-param name="other-elements" select="@template:element"/> 77 </xsl:call-template> 78 </xsl:template> 79 80 <xsl:template name="enter-element"> 81 <xsl:param name="other-elements"/> 82 <xsl:variable name="first-element" select="substring-before($other-elements, ',')"/> 83 <xsl:variable name="remaining-elements" select="substring-after($other-elements, ',')"/> 84 <xsl:choose> 85 <xsl:when test="$first-element = ''"> 86 <xsl:call-template name="next-element"> 87 <xsl:with-param name="first-element" select="$other-elements"/> 88 </xsl:call-template> 89 </xsl:when> 90 <xsl:otherwise> 91 <xsl:call-template name="next-element"> 92 <xsl:with-param name="first-element" select="$first-element"/> 93 <xsl:with-param name="remaining-elements" select="$remaining-elements"/> 94 </xsl:call-template> 95 </xsl:otherwise> 96 </xsl:choose> 97 </xsl:template> 98 99 <xsl:template name="next-element"> 100 <xsl:param name="first-element"/> 101 <xsl:param name="remaining-elements"/> 102 <axsl:for-each select="{$first-element}"> 103 <xsl:choose> 104 <xsl:when test="$remaining-elements = ''"> 105 <xsl:call-template name="enter-attribute"/> 106 </xsl:when> 107 <xsl:otherwise> 108 <xsl:call-template name="enter-element"> 109 <xsl:with-param name="other-elements" select="$remaining-elements"/> 110 </xsl:call-template> 111 </xsl:otherwise> 112 </xsl:choose> 113 </axsl:for-each> 114 </xsl:template> 115 116 117 118 <!-- Match special expression attributes. --> 119 120 <xsl:template match="*[not(@template:if) and not(@template:element) and (@template:attribute or @template:value or @template:expr)]"> 121 <xsl:call-template name="enter-attribute"/> 122 </xsl:template> 123 124 <xsl:template name="enter-attribute"> 125 <xsl:choose> 126 <xsl:when test="@template:attribute"> 127 <axsl:choose> 128 <axsl:when test="@{@template:attribute}"> 129 <axsl:variable name="this-name"><xsl:value-of select="@template:attribute"/></axsl:variable> 130 <axsl:variable name="this-value" select="@{@template:attribute}"/> 131 <xsl:call-template name="special-attributes"/> 132 </axsl:when> 133 <axsl:otherwise> 134 <axsl:variable name="this-name"><xsl:value-of select="@template:attribute"/></axsl:variable> 135 <axsl:variable name="this-value"></axsl:variable> 136 <xsl:call-template name="special-attributes"/> 137 </axsl:otherwise> 138 </axsl:choose> 139 </xsl:when> 140 <xsl:otherwise> 141 <xsl:call-template name="special-attributes"/> 142 </xsl:otherwise> 143 </xsl:choose> 144 </xsl:template> 145 146 <xsl:template name="special-attributes"> 147 <xsl:choose> 148 <xsl:when test="@template:effect = 'replace'"> 149 <xsl:call-template name="special-value"/> 150 </xsl:when> 151 <xsl:otherwise> 152 <xsl:copy> 153 <xsl:apply-templates select="@*"/> 154 <xsl:if test="@template:expr and @template:expr-attr"> 155 <axsl:if test="{@template:expr}"> 156 <axsl:attribute name="{@template:expr-attr}"><xsl:value-of select="@template:expr-attr"/></axsl:attribute> 157 </axsl:if> 158 </xsl:if> 159 <xsl:call-template name="special-value"/> 160 </xsl:copy> 161 </xsl:otherwise> 162 </xsl:choose> 163 </xsl:template> 164 165 <xsl:template name="special-value"> 166 <xsl:choose> 167 <xsl:when test="@template:value"> 168 <axsl:value-of select="{@template:value}"/> 169 </xsl:when> 170 <xsl:otherwise> 171 <xsl:apply-templates select="node()"/> 172 </xsl:otherwise> 173 </xsl:choose> 174 </xsl:template> 175 176 177 178 <!-- Remove template attributes. --> 179 180 <xsl:template match="@template:element|@template:init|@template:attribute|@template:value|@template:expr|@template:expr-attr|@template:effect|@template:if"> 181 </xsl:template> 182 183 184 185 <!-- Replicate unknown elements. --> 186 187 <xsl:template match="@*|node()"> 188 <xsl:copy> 189 <xsl:apply-templates select="@*|node()"/> 190 </xsl:copy> 191 </xsl:template> 192 193 </xsl:stylesheet>