paulb@473 | 1 | <?xml version="1.0"?> |
paulb@473 | 2 | <!-- |
paulb@555 | 3 | Copyright (C) 2006, 2007 Paul Boddie <paul@boddie.org.uk> |
paulb@473 | 4 | |
paulb@473 | 5 | This library is free software; you can redistribute it and/or |
paulb@473 | 6 | modify it under the terms of the GNU Lesser General Public |
paulb@473 | 7 | License as published by the Free Software Foundation; either |
paulb@473 | 8 | version 2.1 of the License, or (at your option) any later version. |
paulb@473 | 9 | |
paulb@473 | 10 | This library is distributed in the hope that it will be useful, |
paulb@473 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@473 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@473 | 13 | Lesser General Public License for more details. |
paulb@473 | 14 | |
paulb@473 | 15 | You should have received a copy of the GNU Lesser General Public |
paulb@473 | 16 | License along with this library; if not, write to the Free Software |
paulb@473 | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@473 | 18 | --> |
paulb@473 | 19 | <xsl:stylesheet version="1.0" |
paulb@473 | 20 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paulb@475 | 21 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template" |
paulb@475 | 22 | xmlns:str="http://exslt.org/strings" |
paulb@475 | 23 | extension-element-prefixes="str"> |
paulb@473 | 24 | |
paulb@475 | 25 | <!-- NOTE: Add various top-level definitions specific to XHTML. --> |
paulb@475 | 26 | |
paulb@475 | 27 | <xsl:output indent="yes" |
paulb@475 | 28 | doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" |
paulb@555 | 29 | doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" |
paulb@555 | 30 | method="xml"/> |
paulb@473 | 31 | |
paulb@535 | 32 | <!-- Get all declared expr-prefix attributes. --> |
paulb@535 | 33 | |
paulb@535 | 34 | <xsl:variable name="prefixes" select="//@expr-prefix"/> |
paulb@535 | 35 | |
paulb@473 | 36 | |
paulb@473 | 37 | |
paulb@507 | 38 | <!-- Process the root element. --> |
paulb@473 | 39 | |
paulb@507 | 40 | <xsl:template match="/"> |
paulb@507 | 41 | <xsl:for-each select="*"> |
paulb@555 | 42 | <!-- NOTE: Stating the namespace using an explicit xmlns attribute. --> |
paulb@507 | 43 | <xsl:element name="{name()}"> |
paulb@555 | 44 | <xsl:attribute name="xmlns"><xsl:value-of select="namespace-uri()"/></xsl:attribute> |
paulb@535 | 45 | <xsl:for-each select="$prefixes"> |
paulb@507 | 46 | <xsl:attribute namespace="{substring-after(string(), ' ')}" name="{substring-before(string(), ' ')}:{name()}"><xsl:value-of select="string()"/></xsl:attribute> |
paulb@507 | 47 | </xsl:for-each> |
paulb@507 | 48 | <xsl:apply-templates select="@*|node()"/> |
paulb@507 | 49 | </xsl:element> |
paulb@507 | 50 | </xsl:for-each> |
paulb@507 | 51 | </xsl:template> |
paulb@507 | 52 | |
paulb@507 | 53 | |
paulb@507 | 54 | |
paulb@507 | 55 | <!-- Remove the mangled template namespace declaration and other declarations. --> |
paulb@507 | 56 | |
paulb@507 | 57 | <xsl:template match="@template|@expr-prefix"> |
paulb@473 | 58 | </xsl:template> |
paulb@473 | 59 | |
paulb@473 | 60 | |
paulb@473 | 61 | |
paulb@473 | 62 | <!-- Match specific template attributes. --> |
paulb@473 | 63 | |
paulb@481 | 64 | <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"> |
paulb@473 | 65 | <!-- Add the namespace. --> |
paulb@473 | 66 | <xsl:attribute name="template:{local-name(.)}"> |
paulb@473 | 67 | <xsl:copy-of select="string(.)"/> |
paulb@473 | 68 | </xsl:attribute> |
paulb@473 | 69 | </xsl:template> |
paulb@473 | 70 | |
paulb@473 | 71 | |
paulb@473 | 72 | |
paulb@475 | 73 | <!-- Fix strings in attributes. --> |
paulb@475 | 74 | |
paulb@475 | 75 | <xsl:template name="fix-string"> |
paulb@475 | 76 | <xsl:copy-of select="str:decode-uri(string(.))"/> |
paulb@475 | 77 | </xsl:template> |
paulb@475 | 78 | |
paulb@475 | 79 | |
paulb@475 | 80 | |
paulb@475 | 81 | <!-- Handle special attributes. --> |
paulb@475 | 82 | |
paulb@475 | 83 | <xsl:template match="@href|@src"> |
paulb@475 | 84 | <xsl:attribute name="{name(.)}"> |
paulb@475 | 85 | <xsl:call-template name="fix-string"/> |
paulb@475 | 86 | </xsl:attribute> |
paulb@475 | 87 | </xsl:template> |
paulb@475 | 88 | |
paulb@475 | 89 | |
paulb@475 | 90 | |
paulb@473 | 91 | <!-- Traverse unknown nodes. --> |
paulb@473 | 92 | |
paulb@473 | 93 | <xsl:template match="@*|node()"> |
paulb@535 | 94 | <xsl:variable name="this-name" select="name()"/> |
paulb@535 | 95 | <xsl:if test="not($prefixes[substring-before(string(), ' ') = $this-name])"> |
paulb@535 | 96 | <xsl:copy> |
paulb@535 | 97 | <xsl:apply-templates select="@*|node()"/> |
paulb@535 | 98 | </xsl:copy> |
paulb@535 | 99 | </xsl:if> |
paulb@473 | 100 | </xsl:template> |
paulb@473 | 101 | |
paulb@473 | 102 | </xsl:stylesheet> |