paulb@233 | 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@412 | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@274 | 18 | --> |
paulb@233 | 19 | <xsl:stylesheet version="1.0" |
paulb@233 | 20 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paulb@233 | 21 | xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" |
paulb@233 | 22 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> |
paulb@233 | 23 | |
paulb@233 | 24 | <xsl:output indent="yes"/> |
paulb@233 | 25 | <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> |
paulb@233 | 26 | |
paulb@233 | 27 | |
paulb@233 | 28 | |
paulb@233 | 29 | <!-- Match the document itself. --> |
paulb@233 | 30 | |
paulb@233 | 31 | <xsl:template match="/"> |
paulb@233 | 32 | <axsl:stylesheet version="1.0"> |
paulb@233 | 33 | |
paulb@233 | 34 | <axsl:output indent="yes"/> |
paulb@233 | 35 | |
paulb@233 | 36 | <axsl:template select="/"> |
paulb@233 | 37 | |
paulb@233 | 38 | <!-- Process the elements. --> |
paulb@233 | 39 | <xsl:apply-templates select="*"/> |
paulb@233 | 40 | |
paulb@233 | 41 | </axsl:template> |
paulb@233 | 42 | |
paulb@233 | 43 | </axsl:stylesheet> |
paulb@233 | 44 | </xsl:template> |
paulb@233 | 45 | |
paulb@233 | 46 | |
paulb@233 | 47 | |
paulb@233 | 48 | <!-- Match element references. --> |
paulb@233 | 49 | |
paulb@233 | 50 | <xsl:template match="*[@template:element]"> |
paulb@233 | 51 | <xsl:call-template name="enter-element"> |
paulb@233 | 52 | <xsl:with-param name="other-elements" select="@template:element"/> |
paulb@233 | 53 | </xsl:call-template> |
paulb@233 | 54 | </xsl:template> |
paulb@233 | 55 | |
paulb@233 | 56 | <xsl:template name="enter-element"> |
paulb@233 | 57 | <xsl:param name="other-elements"/> |
paulb@233 | 58 | <xsl:variable name="first-element" select="substring-before($other-elements, ',')"/> |
paulb@233 | 59 | <xsl:variable name="remaining-elements" select="substring-after($other-elements, ',')"/> |
paulb@233 | 60 | <xsl:choose> |
paulb@233 | 61 | <xsl:when test="$first-element = ''"> |
paulb@233 | 62 | <xsl:call-template name="next-element"> |
paulb@233 | 63 | <xsl:with-param name="first-element" select="$other-elements"/> |
paulb@233 | 64 | </xsl:call-template> |
paulb@233 | 65 | </xsl:when> |
paulb@233 | 66 | <xsl:otherwise> |
paulb@233 | 67 | <xsl:call-template name="next-element"> |
paulb@233 | 68 | <xsl:with-param name="first-element" select="$first-element"/> |
paulb@233 | 69 | <xsl:with-param name="remaining-elements" select="$remaining-elements"/> |
paulb@233 | 70 | </xsl:call-template> |
paulb@233 | 71 | </xsl:otherwise> |
paulb@233 | 72 | </xsl:choose> |
paulb@233 | 73 | </xsl:template> |
paulb@233 | 74 | |
paulb@233 | 75 | <xsl:template name="next-element"> |
paulb@233 | 76 | <xsl:param name="first-element"/> |
paulb@233 | 77 | <xsl:param name="remaining-elements"/> |
paulb@233 | 78 | <axsl:for-each select="{$first-element}"> |
paulb@233 | 79 | <axsl:element name="{$first-element}"> |
paulb@233 | 80 | <xsl:choose> |
paulb@233 | 81 | <xsl:when test="$remaining-elements = ''"> |
paulb@233 | 82 | <xsl:call-template name="enter-attribute"/> |
paulb@233 | 83 | </xsl:when> |
paulb@233 | 84 | <xsl:otherwise> |
paulb@233 | 85 | <xsl:call-template name="enter-element"> |
paulb@233 | 86 | <xsl:with-param name="other-elements" select="$remaining-elements"/> |
paulb@233 | 87 | </xsl:call-template> |
paulb@233 | 88 | </xsl:otherwise> |
paulb@233 | 89 | </xsl:choose> |
paulb@233 | 90 | </axsl:element> |
paulb@233 | 91 | </axsl:for-each> |
paulb@233 | 92 | </xsl:template> |
paulb@233 | 93 | |
paulb@233 | 94 | |
paulb@233 | 95 | |
paulb@233 | 96 | <!-- Match special expression attributes. --> |
paulb@233 | 97 | |
paulb@233 | 98 | <xsl:template match="*[not(@template:element) and @template:attribute]"> |
paulb@233 | 99 | <xsl:call-template name="enter-attribute"/> |
paulb@233 | 100 | </xsl:template> |
paulb@233 | 101 | |
paulb@233 | 102 | <xsl:template name="enter-attribute"> |
paulb@233 | 103 | <xsl:choose> |
paulb@233 | 104 | <xsl:when test="@template:attribute"> |
paulb@233 | 105 | <axsl:choose> |
paulb@233 | 106 | <axsl:when test="@{@template:attribute}"> |
paulb@233 | 107 | <axsl:attribute name="{@template:attribute}"><axsl:value-of select="@{@template:attribute}"/></axsl:attribute> |
paulb@233 | 108 | <xsl:apply-templates select="*"/> |
paulb@233 | 109 | </axsl:when> |
paulb@233 | 110 | <axsl:otherwise> |
paulb@233 | 111 | <axsl:attribute name="{@template:attribute}"/> |
paulb@233 | 112 | <xsl:apply-templates select="*"/> |
paulb@233 | 113 | </axsl:otherwise> |
paulb@233 | 114 | </axsl:choose> |
paulb@233 | 115 | </xsl:when> |
paulb@233 | 116 | <xsl:otherwise> |
paulb@233 | 117 | <xsl:apply-templates select="*"/> |
paulb@233 | 118 | </xsl:otherwise> |
paulb@233 | 119 | </xsl:choose> |
paulb@233 | 120 | </xsl:template> |
paulb@233 | 121 | |
paulb@233 | 122 | |
paulb@233 | 123 | |
paulb@233 | 124 | <!-- Traverse unknown elements. --> |
paulb@233 | 125 | |
paulb@233 | 126 | <xsl:template match="*"> |
paulb@233 | 127 | <xsl:apply-templates select="*"/> |
paulb@233 | 128 | </xsl:template> |
paulb@233 | 129 | |
paulb@233 | 130 | </xsl:stylesheet> |