| 1 | <?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" extension-element-prefixes="saxon" version="2.0"> |
|---|
| 3 | <xsl:output method="text" indent="yes"/> |
|---|
| 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="decimal group list pattern currencyMatch surroundingMatch insertBetween"/> |
|---|
| 7 | <xsl:strip-space elements="*"/> |
|---|
| 8 | |
|---|
| 9 | <xsl:variable name="first" select="true()" saxon:assignable="yes"/> |
|---|
| 10 | |
|---|
| 11 | <xsl:template match="/"> |
|---|
| 12 | <xsl:apply-templates/> |
|---|
| 13 | </xsl:template> |
|---|
| 14 | |
|---|
| 15 | <!-- process ldml,numbers--> |
|---|
| 16 | <xsl:template name="top" match="/ldml"> |
|---|
| 17 | <xsl:choose> |
|---|
| 18 | <xsl:when test="count(./alias)>0"> |
|---|
| 19 | <!-- Handle Alias --> |
|---|
| 20 | <xsl:for-each select="./alias"> |
|---|
| 21 | <xsl:call-template name="alias_template"> |
|---|
| 22 | <xsl:with-param name="templateToCall">top</xsl:with-param> |
|---|
| 23 | <xsl:with-param name="source" select="@source"></xsl:with-param> |
|---|
| 24 | <xsl:with-param name="xpath" select="@path"></xsl:with-param> |
|---|
| 25 | </xsl:call-template> |
|---|
| 26 | </xsl:for-each> |
|---|
| 27 | </xsl:when> |
|---|
| 28 | <xsl:otherwise> |
|---|
| 29 | <!-- ldml --> |
|---|
| 30 | <xsl:if test="name()='ldml'"> |
|---|
| 31 | <!-- numbers --> |
|---|
| 32 | <xsl:for-each select="numbers"> |
|---|
| 33 | <xsl:result-document href="number.js" encoding="UTF-8"><!--<xsl:value-of select="codepoints-to-string(65279)"/>-->// generated from cldr/ldml/main/*.xml, xpath: ldml/numbers |
|---|
| 34 | ({<xsl:call-template name="numbers"></xsl:call-template> |
|---|
| 35 | }) |
|---|
| 36 | </xsl:result-document> |
|---|
| 37 | </xsl:for-each> |
|---|
| 38 | </xsl:if> |
|---|
| 39 | </xsl:otherwise> |
|---|
| 40 | </xsl:choose> |
|---|
| 41 | </xsl:template> |
|---|
| 42 | |
|---|
| 43 | <!-- process numbers--> |
|---|
| 44 | <xsl:template name="numbers" match="numbers"> |
|---|
| 45 | <xsl:choose> |
|---|
| 46 | <xsl:when test="count(./alias)>0"> |
|---|
| 47 | <!-- Handle Alias --> |
|---|
| 48 | <xsl:for-each select="./alias"> |
|---|
| 49 | <xsl:call-template name="alias_template"> |
|---|
| 50 | <xsl:with-param name="templateToCall">numbers</xsl:with-param> |
|---|
| 51 | <xsl:with-param name="source" select="@source"></xsl:with-param> |
|---|
| 52 | <xsl:with-param name="xpath" select="@path"></xsl:with-param> |
|---|
| 53 | </xsl:call-template> |
|---|
| 54 | </xsl:for-each> |
|---|
| 55 | </xsl:when> |
|---|
| 56 | <xsl:otherwise> |
|---|
| 57 | <xsl:apply-templates/> |
|---|
| 58 | </xsl:otherwise> |
|---|
| 59 | </xsl:choose> |
|---|
| 60 | </xsl:template> |
|---|
| 61 | |
|---|
| 62 | <!-- process symbols --> |
|---|
| 63 | <xsl:template name="symbols" match="symbols"> |
|---|
| 64 | <xsl:choose> |
|---|
| 65 | <xsl:when test="count(./alias)>0"> |
|---|
| 66 | <!-- Handle Alias --> |
|---|
| 67 | <xsl:for-each select="./alias"> |
|---|
| 68 | <xsl:call-template name="alias_template"> |
|---|
| 69 | <xsl:with-param name="templateToCall">symbols</xsl:with-param> |
|---|
| 70 | <xsl:with-param name="source" select="@source"></xsl:with-param> |
|---|
| 71 | <xsl:with-param name="xpath" select="@path"></xsl:with-param> |
|---|
| 72 | </xsl:call-template> |
|---|
| 73 | </xsl:for-each> |
|---|
| 74 | </xsl:when> |
|---|
| 75 | <xsl:otherwise> |
|---|
| 76 | <xsl:for-each select="*"> |
|---|
| 77 | <xsl:call-template name="insert_comma"/> |
|---|
| 78 | '<xsl:value-of select="name()"></xsl:value-of> |
|---|
| 79 | <xsl:text>':"</xsl:text> |
|---|
| 80 | <xsl:value-of select="."></xsl:value-of> |
|---|
| 81 | <xsl:text>"</xsl:text> |
|---|
| 82 | <!--xsl:if test="count(following-sibling::*)>0 |
|---|
| 83 | or count(parent::node()/following-sibling::*)>0"> |
|---|
| 84 | <xsl:text>,</xsl:text> |
|---|
| 85 | </xsl:if--> |
|---|
| 86 | </xsl:for-each> |
|---|
| 87 | </xsl:otherwise> |
|---|
| 88 | </xsl:choose> |
|---|
| 89 | </xsl:template> |
|---|
| 90 | |
|---|
| 91 | <!-- process decimalFormats | scientificFormats | percentFormats | currencyFormats --> |
|---|
| 92 | <xsl:template name="formats" match="decimalFormats | scientificFormats | percentFormats | currencyFormats"> |
|---|
| 93 | <xsl:param name="width" select="@type"></xsl:param> |
|---|
| 94 | <xsl:choose> |
|---|
| 95 | <xsl:when test="count(./alias)>0"> |
|---|
| 96 | <!-- Handle Alias --> |
|---|
| 97 | <xsl:for-each select="./alias"> |
|---|
| 98 | <xsl:call-template name="alias_template"> |
|---|
| 99 | <xsl:with-param name="templateToCall">formats</xsl:with-param> |
|---|
| 100 | <xsl:with-param name="source" select="@source"></xsl:with-param> |
|---|
| 101 | <xsl:with-param name="xpath" select="@path"></xsl:with-param> |
|---|
| 102 | </xsl:call-template> |
|---|
| 103 | </xsl:for-each> |
|---|
| 104 | </xsl:when> |
|---|
| 105 | <xsl:otherwise> |
|---|
| 106 | <xsl:choose> |
|---|
| 107 | <xsl:when test="contains(name(),'Formats')"> |
|---|
| 108 | <xsl:for-each select="*"> |
|---|
| 109 | <xsl:call-template name="formats"></xsl:call-template> |
|---|
| 110 | </xsl:for-each> |
|---|
| 111 | </xsl:when> |
|---|
| 112 | <xsl:otherwise> |
|---|
| 113 | <xsl:if test="name()!='default'"> |
|---|
| 114 | <xsl:if test="name()='currencySpacing'"> |
|---|
| 115 | <xsl:call-template name="currencySpacing"></xsl:call-template> |
|---|
| 116 | </xsl:if><xsl:for-each select=".//pattern"> |
|---|
| 117 | <xsl:call-template name="insert_comma"/> |
|---|
| 118 | '<xsl:value-of select="name(..)"></xsl:value-of> |
|---|
| 119 | <xsl:if test="string-length($width)>0"> |
|---|
| 120 | <xsl:text>-</xsl:text> |
|---|
| 121 | <xsl:value-of select="$width"></xsl:value-of> |
|---|
| 122 | </xsl:if> |
|---|
| 123 | <xsl:text>':"</xsl:text><xsl:value-of select="."/> |
|---|
| 124 | <xsl:text>"</xsl:text> |
|---|
| 125 | <!--xsl:if test="count(parent::node()/parent::node()/following-sibling::*)>0 |
|---|
| 126 | or count(parent::node()/parent::node()/parent::node()/following-sibling::*)>0"> |
|---|
| 127 | <xsl:text>,</xsl:text> |
|---|
| 128 | </xsl:if--> |
|---|
| 129 | </xsl:for-each> |
|---|
| 130 | </xsl:if> |
|---|
| 131 | </xsl:otherwise> |
|---|
| 132 | </xsl:choose> |
|---|
| 133 | </xsl:otherwise> |
|---|
| 134 | </xsl:choose> |
|---|
| 135 | </xsl:template> |
|---|
| 136 | |
|---|
| 137 | <!-- process currencySpacing --> |
|---|
| 138 | <xsl:template name="currencySpacing"> |
|---|
| 139 | <xsl:choose> |
|---|
| 140 | <xsl:when test="count(./alias)>0"> |
|---|
| 141 | <!-- Handle Alias --> |
|---|
| 142 | <xsl:for-each select="./alias"> |
|---|
| 143 | <xsl:call-template name="alias_template"> |
|---|
| 144 | <xsl:with-param name="templateToCall">symbols</xsl:with-param> |
|---|
| 145 | <xsl:with-param name="source" select="@source"></xsl:with-param> |
|---|
| 146 | <xsl:with-param name="xpath" select="@path"></xsl:with-param> |
|---|
| 147 | </xsl:call-template> |
|---|
| 148 | </xsl:for-each> |
|---|
| 149 | </xsl:when> |
|---|
| 150 | <xsl:otherwise> |
|---|
| 151 | <xsl:choose> |
|---|
| 152 | <xsl:when test="name()='currencySpacing' |
|---|
| 153 | or name()='beforeCurrency' |
|---|
| 154 | or name()='afterCurrency'" > |
|---|
| 155 | <xsl:for-each select="*"> |
|---|
| 156 | <xsl:call-template name="currencySpacing"></xsl:call-template> |
|---|
| 157 | </xsl:for-each> |
|---|
| 158 | </xsl:when> |
|---|
| 159 | <xsl:otherwise> |
|---|
| 160 | <xsl:call-template name="insert_comma"/> |
|---|
| 161 | '<xsl:value-of select="name(../..)"></xsl:value-of> |
|---|
| 162 | <xsl:text>-</xsl:text> |
|---|
| 163 | <xsl:value-of select="name(..)"></xsl:value-of> |
|---|
| 164 | <xsl:text>-</xsl:text> |
|---|
| 165 | <xsl:value-of select="name()"></xsl:value-of> |
|---|
| 166 | <xsl:text>':"</xsl:text> |
|---|
| 167 | <xsl:value-of select="." ></xsl:value-of> |
|---|
| 168 | <xsl:text>"</xsl:text> |
|---|
| 169 | <!--xsl:if test="count(following-sibling::*)>0 |
|---|
| 170 | or count(parent::node()/following-sibling::*)>0 |
|---|
| 171 | or count(parent::node()/parent::node()/following-sibling::*)>0 |
|---|
| 172 | or count(parent::node()/parent::node()/parent::node()/following-sibling::*)>0"> |
|---|
| 173 | <xsl:text>,</xsl:text> |
|---|
| 174 | </xsl:if--> |
|---|
| 175 | </xsl:otherwise> |
|---|
| 176 | </xsl:choose> |
|---|
| 177 | </xsl:otherwise> |
|---|
| 178 | </xsl:choose> |
|---|
| 179 | </xsl:template> |
|---|
| 180 | |
|---|
| 181 | <xsl:template name="currencies" match="currencies"></xsl:template> |
|---|
| 182 | |
|---|
| 183 | <!-- recursive process for alias --> |
|---|
| 184 | <xsl:template name="alias_template"> |
|---|
| 185 | <xsl:param name="templateToCall"></xsl:param> |
|---|
| 186 | <xsl:param name="source"></xsl:param> |
|---|
| 187 | <xsl:param name="xpath"></xsl:param> |
|---|
| 188 | |
|---|
| 189 | <xsl:variable name="cur_width" select="../@type"></xsl:variable> |
|---|
| 190 | |
|---|
| 191 | <xsl:choose> |
|---|
| 192 | <!-- source="locale" --> |
|---|
| 193 | <xsl:when test="$source='locale'"> |
|---|
| 194 | <xsl:for-each select="saxon:evaluate(concat('../',$xpath))"> |
|---|
| 195 | <xsl:call-template name="invoke_template_by_name"> |
|---|
| 196 | <xsl:with-param name="templateName" select="$templateToCall"></xsl:with-param> |
|---|
| 197 | <xsl:with-param name="width" select="$cur_width"></xsl:with-param> |
|---|
| 198 | </xsl:call-template> |
|---|
| 199 | </xsl:for-each> |
|---|
| 200 | </xsl:when> |
|---|
| 201 | <xsl:otherwise> |
|---|
| 202 | <!-- source is an external xml file --> |
|---|
| 203 | <xsl:if test="string-length($xpath)>0"> |
|---|
| 204 | <xsl:for-each select="doc(concat($source,'.xml'))"> |
|---|
| 205 | <xsl:for-each select="saxon:evaluate($xpath)"> |
|---|
| 206 | <xsl:call-template name="invoke_template_by_name"> |
|---|
| 207 | <xsl:with-param name="templateName" select="$templateToCall"></xsl:with-param> |
|---|
| 208 | <xsl:with-param name="width" select="$cur_width"></xsl:with-param> |
|---|
| 209 | </xsl:call-template> |
|---|
| 210 | </xsl:for-each> |
|---|
| 211 | </xsl:for-each> |
|---|
| 212 | </xsl:if> |
|---|
| 213 | </xsl:otherwise> |
|---|
| 214 | </xsl:choose> |
|---|
| 215 | </xsl:template> |
|---|
| 216 | |
|---|
| 217 | <!-- too bad that can only use standard xsl:call-template(name can not be variable) |
|---|
| 218 | error occurs if use <saxson:call-templates($templateToCall) /> --> |
|---|
| 219 | <xsl:template name="invoke_template_by_name"> |
|---|
| 220 | <xsl:param name="templateName"></xsl:param> |
|---|
| 221 | <xsl:param name="width"></xsl:param> |
|---|
| 222 | <xsl:if test="$templateName='top'"> |
|---|
| 223 | <xsl:call-template name="top"></xsl:call-template> |
|---|
| 224 | </xsl:if> |
|---|
| 225 | <xsl:if test="$templateName='numbers'"> |
|---|
| 226 | <xsl:call-template name="numbers"></xsl:call-template> |
|---|
| 227 | </xsl:if> |
|---|
| 228 | <xsl:if test="$templateName='symbols'"> |
|---|
| 229 | <xsl:call-template name="symbols"></xsl:call-template> |
|---|
| 230 | </xsl:if> |
|---|
| 231 | <xsl:if test="$templateName='formats'"> |
|---|
| 232 | <xsl:call-template name="formats"> |
|---|
| 233 | <xsl:with-param name="width" select="$width"></xsl:with-param> |
|---|
| 234 | </xsl:call-template> |
|---|
| 235 | </xsl:if> |
|---|
| 236 | <xsl:if test="$templateName='currencySpacing'"> |
|---|
| 237 | <xsl:call-template name="currencySpacing"></xsl:call-template> |
|---|
| 238 | </xsl:if> |
|---|
| 239 | </xsl:template> |
|---|
| 240 | |
|---|
| 241 | <xsl:template name="insert_comma"> |
|---|
| 242 | <xsl:choose> |
|---|
| 243 | <xsl:when test="$first"> |
|---|
| 244 | <saxon:assign name="first" select="false()"/> |
|---|
| 245 | </xsl:when> |
|---|
| 246 | <xsl:otherwise> |
|---|
| 247 | <xsl:text>,</xsl:text> |
|---|
| 248 | </xsl:otherwise> |
|---|
| 249 | </xsl:choose> |
|---|
| 250 | </xsl:template> |
|---|
| 251 | </xsl:stylesheet> |
|---|