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 36 <axsl:template select="/"> 37 38 <!-- Process the elements. --> 39 <xsl:apply-templates select="*"/> 40 41 </axsl:template> 42 43 </axsl:stylesheet> 44 </xsl:template> 45 46 47 48 <!-- Match element references. --> 49 50 <xsl:template match="*[@template:element]"> 51 <xsl:call-template name="enter-element"> 52 <xsl:with-param name="other-elements" select="@template:element"/> 53 </xsl:call-template> 54 </xsl:template> 55 56 <xsl:template name="enter-element"> 57 <xsl:param name="other-elements"/> 58 <xsl:variable name="first-element" select="substring-before($other-elements, ',')"/> 59 <xsl:variable name="remaining-elements" select="substring-after($other-elements, ',')"/> 60 <xsl:choose> 61 <xsl:when test="$first-element = ''"> 62 <xsl:call-template name="next-element"> 63 <xsl:with-param name="first-element" select="$other-elements"/> 64 </xsl:call-template> 65 </xsl:when> 66 <xsl:otherwise> 67 <xsl:call-template name="next-element"> 68 <xsl:with-param name="first-element" select="$first-element"/> 69 <xsl:with-param name="remaining-elements" select="$remaining-elements"/> 70 </xsl:call-template> 71 </xsl:otherwise> 72 </xsl:choose> 73 </xsl:template> 74 75 <xsl:template name="next-element"> 76 <xsl:param name="first-element"/> 77 <xsl:param name="remaining-elements"/> 78 <axsl:for-each select="{$first-element}"> 79 <axsl:element name="{$first-element}"> 80 <xsl:choose> 81 <xsl:when test="$remaining-elements = ''"> 82 <xsl:call-template name="enter-attribute"/> 83 </xsl:when> 84 <xsl:otherwise> 85 <xsl:call-template name="enter-element"> 86 <xsl:with-param name="other-elements" select="$remaining-elements"/> 87 </xsl:call-template> 88 </xsl:otherwise> 89 </xsl:choose> 90 </axsl:element> 91 </axsl:for-each> 92 </xsl:template> 93 94 95 96 <!-- Match special expression attributes. --> 97 98 <xsl:template match="*[not(@template:element) and @template:attribute]"> 99 <xsl:call-template name="enter-attribute"/> 100 </xsl:template> 101 102 <xsl:template name="enter-attribute"> 103 <xsl:choose> 104 <xsl:when test="@template:attribute"> 105 <axsl:choose> 106 <axsl:when test="@{@template:attribute}"> 107 <axsl:attribute name="{@template:attribute}"><axsl:value-of select="@{@template:attribute}"/></axsl:attribute> 108 <xsl:apply-templates select="*"/> 109 </axsl:when> 110 <axsl:otherwise> 111 <axsl:attribute name="{@template:attribute}"/> 112 <xsl:apply-templates select="*"/> 113 </axsl:otherwise> 114 </axsl:choose> 115 </xsl:when> 116 <xsl:otherwise> 117 <xsl:apply-templates select="*"/> 118 </xsl:otherwise> 119 </xsl:choose> 120 </xsl:template> 121 122 123 124 <!-- Traverse unknown elements. --> 125 126 <xsl:template match="*"> 127 <xsl:apply-templates select="*"/> 128 </xsl:template> 129 130 </xsl:stylesheet>