XSLTools

XSLForms/XSL/FixNamespace.xsl

522:44f29f525fc7
2006-03-12 paulb [project @ 2006-03-12 22:37:41 by paulb] Made the non-installed package and examples override any installed software.
     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     32     33   <!-- Process the root element. -->    34     35   <xsl:template match="/">    36     <xsl:for-each select="*">    37       <!-- NOTE: Not stating the namespace explicitly. -->    38       <xsl:element name="{name()}">    39         <xsl:for-each select="//@expr-prefix">    40           <xsl:attribute namespace="{substring-after(string(), ' ')}" name="{substring-before(string(), ' ')}:{name()}"><xsl:value-of select="string()"/></xsl:attribute>    41         </xsl:for-each>    42         <xsl:apply-templates select="@*|node()"/>    43       </xsl:element>    44     </xsl:for-each>    45   </xsl:template>    46     47     48     49   <!-- Remove the mangled template namespace declaration and other declarations. -->    50     51   <xsl:template match="@template|@expr-prefix">    52   </xsl:template>    53     54     55     56   <!-- Match specific template attributes. -->    57     58   <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">    59     <!-- Add the namespace. -->    60     <xsl:attribute name="template:{local-name(.)}">    61       <xsl:copy-of select="string(.)"/>    62     </xsl:attribute>    63   </xsl:template>    64     65     66     67   <!-- Fix strings in attributes. -->    68     69   <xsl:template name="fix-string">    70     <xsl:copy-of select="str:decode-uri(string(.))"/>    71   </xsl:template>    72     73     74     75   <!-- Handle special attributes. -->    76     77   <xsl:template match="@href|@src">    78     <xsl:attribute name="{name(.)}">    79       <xsl:call-template name="fix-string"/>    80     </xsl:attribute>    81   </xsl:template>    82     83     84     85   <!-- Traverse unknown nodes. -->    86     87   <xsl:template match="@*|node()">    88     <xsl:copy>    89       <xsl:apply-templates select="@*|node()"/>    90     </xsl:copy>    91   </xsl:template>    92     93 </xsl:stylesheet>