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