1 <?xml version="1.0"?> 2 <!-- 3 Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 18 --> 19 <xsl:stylesheet version="1.0" 20 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 21 xmlns:template="http://www.boddie.org.uk/ns/xmltools/template" 22 xmlns:str="http://exslt.org/strings" 23 extension-element-prefixes="str"> 24 25 <!-- NOTE: Add various top-level definitions specific to XHTML. --> 26 27 <xsl:output indent="yes" 28 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 29 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> 30 31 <!-- Get all declared expr-prefix attributes. --> 32 33 <xsl:variable name="prefixes" select="//@expr-prefix"/> 34 35 36 37 <!-- Process the root element. --> 38 39 <xsl:template match="/"> 40 <xsl:for-each select="*"> 41 <!-- NOTE: Not stating the namespace explicitly. --> 42 <xsl:element name="{name()}"> 43 <xsl:for-each select="$prefixes"> 44 <xsl:attribute namespace="{substring-after(string(), ' ')}" name="{substring-before(string(), ' ')}:{name()}"><xsl:value-of select="string()"/></xsl:attribute> 45 </xsl:for-each> 46 <xsl:apply-templates select="@*|node()"/> 47 </xsl:element> 48 </xsl:for-each> 49 </xsl:template> 50 51 52 53 <!-- Remove the mangled template namespace declaration and other declarations. --> 54 55 <xsl:template match="@template|@expr-prefix"> 56 </xsl:template> 57 58 59 60 <!-- Match specific template attributes. --> 61 62 <xsl:template match="@if|@element|@attribute|@attribute-field|@attribute-area|@attribute-button|@attribute-list-button|@selector-field|@multiple-choice-field|@multiple-choice-list-field|@multiple-choice-value|@multiple-choice-list-value|@multiple-choice-list-element|@effect|@value|@expr|@expr-attr|@i18n|@copy"> 63 <!-- Add the namespace. --> 64 <xsl:attribute name="template:{local-name(.)}"> 65 <xsl:copy-of select="string(.)"/> 66 </xsl:attribute> 67 </xsl:template> 68 69 70 71 <!-- Fix strings in attributes. --> 72 73 <xsl:template name="fix-string"> 74 <xsl:copy-of select="str:decode-uri(string(.))"/> 75 </xsl:template> 76 77 78 79 <!-- Handle special attributes. --> 80 81 <xsl:template match="@href|@src"> 82 <xsl:attribute name="{name(.)}"> 83 <xsl:call-template name="fix-string"/> 84 </xsl:attribute> 85 </xsl:template> 86 87 88 89 <!-- Traverse unknown nodes. --> 90 91 <xsl:template match="@*|node()"> 92 <xsl:variable name="this-name" select="name()"/> 93 <xsl:if test="not($prefixes[substring-before(string(), ' ') = $this-name])"> 94 <xsl:copy> 95 <xsl:apply-templates select="@*|node()"/> 96 </xsl:copy> 97 </xsl:if> 98 </xsl:template> 99 100 </xsl:stylesheet>