Show
Ignore:
Timestamp:
03/12/07 19:36:41 (22 months ago)
Author:
peller
Message:

XSLT to generate currency.js tables for dojo.i18n, from Evan Huang (IBM, CCLA). References #2326

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildscripts/cldrCurrency.xsl

    r7204 r7576  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <xsl:stylesheet xmlns:saxon="http://saxon.sf.net/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
     2<xsl:stylesheet xmlns:saxon="http://saxon.sf.net/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="saxon" version="2.0"> 
    33<xsl:output method="text" indent="yes"/> 
    4 <xsl:strip-space elements="*"/>  
    5      
     4<!-- list the data elements whose spaces should be preserved 
     5       it seems listing only the parent node doesn't work --> 
     6<xsl:preserve-space elements="displayName symbol"/> 
     7<xsl:strip-space elements="*"/> 
     8 
     9<!--  currencyList is an external string property like "AUD|BEF|CAD|CHF|CNY|DEM|...|USD", 
     10        if it is provided, only those currencies in this list will be extracted, 
     11        otherwise all the currencies will be extracted by default--> 
     12<xsl:param name="currencyList"></xsl:param> 
     13<xsl:variable name="first" select="true()" saxon:assignable="yes"/> 
     14 
    615<xsl:template match="/"> 
    716     <xsl:apply-templates/> 
    817</xsl:template> 
    9    
     18 
    1019<!-- process ldml, numbers and currencies --> 
    1120<xsl:template name="top" match="/ldml"> 
     
    2433            <xsl:choose> 
    2534                <xsl:when test="name()='currencies'"> 
    26                     <!-- currencies --> 
    27                     <xsl:for-each select="currency"> 
    28                         <xsl:value-of select="@type"></xsl:value-of> 
    29                         <xsl:result-document href="{concat(@type,'.js')}" encoding="UTF-8">// generated from cldr/ldml/main/*.xml, xpath: ldml/numbers/currencies 
    30 ({<xsl:call-template name="currency"></xsl:call-template> 
     35                    <xsl:result-document href="currency.js" encoding="UTF-8">// generated from cldr/ldml/main/*.xml, xpath: ldml/numbers/currencies 
     36({<xsl:choose><xsl:when test="string-length(string($currencyList))>0">                             
     37                                 <xsl:for-each select="currency"> 
     38                                     <xsl:if test="contains($currencyList,@type)"> 
     39                                         <xsl:call-template name="currency"></xsl:call-template> 
     40                                     </xsl:if> 
     41                                 </xsl:for-each> 
     42                         </xsl:when> 
     43                         <xsl:otherwise> 
     44                             <xsl:for-each select="currency"> 
     45                                 <xsl:call-template name="currency"></xsl:call-template>                         
     46                             </xsl:for-each> 
     47                         </xsl:otherwise> 
     48                     </xsl:choose> 
    3149}) 
    32                         </xsl:result-document> 
    33                     </xsl:for-each> 
     50                 </xsl:result-document> 
    3451                </xsl:when> 
    3552                <xsl:otherwise> 
    3653                    <xsl:if test="name()='ldml'"> 
    3754                        <!-- ldml --> 
    38                         <xsl:for-each select="numbers"> 
     55                        <xsl:for-each select="numbers">     
    3956                            <xsl:call-template name="top"></xsl:call-template> 
    4057                        </xsl:for-each> 
     
    6784        </xsl:when> 
    6885        <xsl:otherwise> 
    69             <xsl:for-each select="*[not(@draft)] | *[@draft!='provisional' and @draft!='unconfirmed']"> 
    70         '<xsl:value-of select="name()"></xsl:value-of> 
    71                 <xsl:text>': "</xsl:text>  
    72                 <xsl:value-of select="replace(.,'&quot;', '\\&quot;')"></xsl:value-of>                 
    73                 <xsl:text>"</xsl:text> 
    74                 <xsl:if test="count((following-sibling::node())[not(@draft)]  
    75                            | *[@draft!='provisional' and @draft!='unconfirmed']) > 0 "> 
    76                     <xsl:text>,</xsl:text> 
    77                 </xsl:if> 
    78             </xsl:for-each>             
     86        <xsl:if test="count(./* [(not(@draft) or @draft!='provisional' and @draft!='unconfirmed')]) > 0"> 
     87            <xsl:call-template name="insert_comma"/> 
     88            <xsl:text> 
     89        </xsl:text> 
     90            <xsl:value-of select="@type"></xsl:value-of> 
     91            <xsl:text>:{</xsl:text> 
     92             <xsl:for-each select="*[not(@draft)] | *[@draft!='provisional' and @draft!='unconfirmed']"> 
     93                    <xsl:value-of select="name()"></xsl:value-of> 
     94                    <xsl:text>:"</xsl:text>  
     95                    <xsl:value-of select="replace(.,'&quot;', '\\&quot;')"></xsl:value-of>                 
     96                    <xsl:text>"</xsl:text> 
     97                    <xsl:if test="count((following-sibling::node())[not(@draft)]  
     98                               | *[@draft!='provisional' and @draft!='unconfirmed']) > 0 "> 
     99                    <xsl:text>, </xsl:text> 
     100                    </xsl:if> 
     101             </xsl:for-each> 
     102            <xsl:text>}</xsl:text> 
     103            </xsl:if> 
    79104         </xsl:otherwise>    
    80105        </xsl:choose> 
     
    124149    </xsl:template>    
    125150 
     151    <xsl:template name="insert_comma"> 
     152        <xsl:choose> 
     153            <xsl:when test="$first"> 
     154                <saxon:assign name="first" select="false()"/> 
     155            </xsl:when> 
     156            <xsl:otherwise> 
     157                <xsl:text>,</xsl:text> 
     158            </xsl:otherwise> 
     159        </xsl:choose> 
     160    </xsl:template> 
     161     
    126162</xsl:stylesheet>