paul@688 | 1 | <?xml version="1.0"?> |
paul@688 | 2 | <!-- |
paul@688 | 3 | Copyright (C) 2009 Paul Boddie <paul@boddie.org.uk> |
paul@688 | 4 | |
paul@688 | 5 | This program is free software; you can redistribute it and/or modify it under |
paul@688 | 6 | the terms of the GNU Lesser General Public License as published by the Free |
paul@688 | 7 | Software Foundation; either version 3 of the License, or (at your option) any |
paul@688 | 8 | later version. |
paul@688 | 9 | |
paul@688 | 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@688 | 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@688 | 12 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
paul@688 | 13 | details. |
paul@688 | 14 | |
paul@688 | 15 | You should have received a copy of the GNU Lesser General Public License along |
paul@688 | 16 | with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@688 | 17 | --> |
paul@688 | 18 | <xsl:stylesheet version="1.0" |
paul@688 | 19 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paul@688 | 20 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> |
paul@688 | 21 | |
paul@688 | 22 | <xsl:output indent="yes" method="xml"/> |
paul@688 | 23 | |
paul@688 | 24 | <!-- Process the root element. --> |
paul@688 | 25 | |
paul@688 | 26 | <xsl:template match="/"> |
paul@688 | 27 | <translations> |
paul@688 | 28 | <locale> |
paul@688 | 29 | <xsl:apply-templates select="@*|node()"/> |
paul@688 | 30 | </locale> |
paul@688 | 31 | </translations> |
paul@688 | 32 | </xsl:template> |
paul@688 | 33 | |
paul@688 | 34 | |
paul@688 | 35 | |
paul@688 | 36 | <!-- Handle elements with translation attributes. --> |
paul@688 | 37 | |
paul@688 | 38 | <xsl:template match="*[@template:i18n]"> |
paul@688 | 39 | <xsl:choose> |
paul@688 | 40 | <xsl:when test="@template:i18n = '-'"> |
paul@688 | 41 | <translation> |
paul@688 | 42 | <xsl:attribute name="value"> |
paul@688 | 43 | <xsl:copy-of select="text()"/> |
paul@688 | 44 | </xsl:attribute> |
paul@688 | 45 | </translation> |
paul@688 | 46 | </xsl:when> |
paul@688 | 47 | <xsl:otherwise> |
paul@688 | 48 | <translation value="{@template:i18n}"></translation> |
paul@688 | 49 | </xsl:otherwise> |
paul@688 | 50 | </xsl:choose> |
paul@689 | 51 | <xsl:apply-templates select="@*|node()"/> |
paul@689 | 52 | </xsl:template> |
paul@689 | 53 | |
paul@689 | 54 | |
paul@689 | 55 | |
paul@689 | 56 | <!-- Handle attributes containing translation functions. --> |
paul@689 | 57 | |
paul@689 | 58 | <xsl:template match="@*[contains(string(), 'template:i18n')]"> |
paul@689 | 59 | <xsl:variable name="after-parameter">template:i18n('</xsl:variable> |
paul@689 | 60 | <xsl:variable name="before-parameter">')</xsl:variable> |
paul@689 | 61 | <xsl:variable name="after" select="substring-after(string(), $after-parameter)"/> |
paul@689 | 62 | <xsl:variable name="fragment" select="substring-before($after, $before-parameter)"/> |
paul@689 | 63 | <translation value="{$fragment}"></translation> |
paul@688 | 64 | </xsl:template> |
paul@688 | 65 | |
paul@688 | 66 | |
paul@688 | 67 | |
paul@688 | 68 | <!-- Traverse unknown nodes. --> |
paul@688 | 69 | |
paul@688 | 70 | <xsl:template match="@*|node()"> |
paul@688 | 71 | <xsl:apply-templates select="@*|node()"/> |
paul@688 | 72 | </xsl:template> |
paul@688 | 73 | |
paul@688 | 74 | </xsl:stylesheet> |