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