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