XML to CSV Transpose by Dates

亡梦爱人 提交于 2019-12-08 05:36:20

问题


Using XSLT 1.0, I am attempting to convert an XML file to CSV, specifically to transpose the data from full dates to pivoted month columns with Year and Day indicators.

XML comprises of Google Doodles in long format of dates and doodle name. Below is 2010 data for first 6 months:

<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
  <GoogleDoodles>
    <ID>12</ID>
    <DoodleDate>2010-02-06</DoodleDate>
    <Doodle>Sami National Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>17</ID>
    <DoodleDate>2010-02-09</DoodleDate>
    <Doodle>Natsume Soseki's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>18</ID>
    <DoodleDate>2010-02-02</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - New Zealand Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>19</ID>
    <DoodleDate>2010-02-03</DoodleDate>
    <Doodle>Norman Rockwell's 106th Birthday - © 1926 SEPS by Curtis Publishing</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>26</ID>
    <DoodleDate>2010-02-11</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Opening Ceremony (Asia)</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>27</ID>
    <DoodleDate>2010-02-11</DoodleDate>
    <Doodle>Napoleon Orda's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>28</ID>
    <DoodleDate>2010-02-11</DoodleDate>
    <Doodle>New Year Celebration 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>33</ID>
    <DoodleDate>2010-02-11</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Opening Ceremony</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>40</ID>
    <DoodleDate>2010-02-12</DoodleDate>
    <Doodle>Carnival 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>41</ID>
    <DoodleDate>2010-06-06</DoodleDate>
    <Doodle>Sweden National Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>42</ID>
    <DoodleDate>2010-06-08</DoodleDate>
    <Doodle>Robert Schumann's 200th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>50</ID>
    <DoodleDate>2010-02-12</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Luge</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>51</ID>
    <DoodleDate>2010-06-02</DoodleDate>
    <Doodle>Republic Day Italy 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>52</ID>
    <DoodleDate>2010-06-05</DoodleDate>
    <Doodle>Dennis Gabor´s 110th birthday - Holography support courtesy of the Departments of Electrical http://stackoverflow.com/questions/2972445/xml-to-csv-problemEngineering and Applied Physics at Stanford University</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>68</ID>
    <DoodleDate>2010-02-13</DoodleDate>
    <Doodle>Lunar New Year's Eve 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>69</ID>
    <DoodleDate>2010-02-13</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Snowboarding</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>70</ID>
    <DoodleDate>2010-06-11</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - South Africa Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>71</ID>
    <DoodleDate>2010-06-09</DoodleDate>
    <Doodle>Argentina Independence Day / Doodle for Google 2010 - Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>72</ID>
    <DoodleDate>2010-06-11</DoodleDate>
    <Doodle>Jacques Cousteau's 100th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>79</ID>
    <DoodleDate>2010-02-14</DoodleDate>
    <Doodle>Valentine's Day / 2010 Vancouver Olympic Games - Pairs Skating</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>80</ID>
    <DoodleDate>2010-06-11</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - France Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>81</ID>
    <DoodleDate>2010-06-11</DoodleDate>
    <Doodle>World Cup 2010 Final</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>85</ID>
    <DoodleDate>2010-02-14</DoodleDate>
    <Doodle>Lunar New Year 2010 - Multiple Countries</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>86</ID>
    <DoodleDate>2010-06-11</DoodleDate>
    <Doodle>World Cup 2010 Opening Day</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>87</ID>
    <DoodleDate>2010-06-12</DoodleDate>
    <Doodle>Russia Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>88</ID>
    <DoodleDate>2010-06-12</DoodleDate>
    <Doodle>Valentine's Day 2010 - Brazil</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>98</ID>
    <DoodleDate>2010-02-15</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Cross Country Skiing</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>106</ID>
    <DoodleDate>2010-02-16</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Curling</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>107</ID>
    <DoodleDate>2010-06-12</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Korea Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>108</ID>
    <DoodleDate>2010-06-12</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - UK by Daniel Joel</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>119</ID>
    <DoodleDate>2010-02-17</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Skiing</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>120</ID>
    <DoodleDate>2010-06-12</DoodleDate>
    <Doodle>Philippines Independence Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>121</ID>
    <DoodleDate>2010-06-13</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Australia Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>122</ID>
    <DoodleDate>2010-06-13</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Germany Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>129</ID>
    <DoodleDate>2010-02-21</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Bobsleigh</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>130</ID>
    <DoodleDate>2010-06-13</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Ghana Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>131</ID>
    <DoodleDate>2010-06-13</DoodleDate>
    <Doodle>Asteroid Explorer Hayabusa Returns</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>132</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Netherlands Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>139</ID>
    <DoodleDate>2010-05-01</DoodleDate>
    <Doodle>Labour Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>140</ID>
    <DoodleDate>2010-02-19</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Ski Jump</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>141</ID>
    <DoodleDate>2010-02-19</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Alpine Skiing</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>142</ID>
    <DoodleDate>2010-02-18</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Skeleton</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>143</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - UAE Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>148</ID>
    <DoodleDate>2010-05-01</DoodleDate>
    <Doodle>World Expo Opens in Shanghai</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>149</ID>
    <DoodleDate>2010-05-05</DoodleDate>
    <Doodle>Rocket Festival</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>150</ID>
    <DoodleDate>2010-05-05</DoodleDate>
    <Doodle>Patios Cordobeses</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>151</ID>
    <DoodleDate>2010-02-24</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Ice Hockey</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>152</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Israel Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>156</ID>
    <DoodleDate>2010-05-02</DoodleDate>
    <Doodle>Mother's Day 2010 - Multiple Countries on Various Dates</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>157</ID>
    <DoodleDate>2010-05-04</DoodleDate>
    <Doodle>Umm Kalthum's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>158</ID>
    <DoodleDate>2010-02-27</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Speed Skating</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>159</ID>
    <DoodleDate>2010-02-26</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Short Track</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>160</ID>
    <DoodleDate>2010-02-22</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Figure Skating</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>161</ID>
    <DoodleDate>2010-02-23</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Freestyle Skiing</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>162</ID>
    <DoodleDate>2010-02-25</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Nordic</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>163</ID>
    <DoodleDate>2010-02-25</DoodleDate>
    <Doodle>Kuwait National Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>164</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Kenya Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>165</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Hong Kong Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>166</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Italy Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>167</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Czech Republic Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>170</ID>
    <DoodleDate>2010-05-06</DoodleDate>
    <Doodle>U.K. Election Day</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>171</ID>
    <DoodleDate>2010-04-02</DoodleDate>
    <Doodle>Hans Christian Andersen's 205th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>172</ID>
    <DoodleDate>2010-02-28</DoodleDate>
    <Doodle>2010 Vancouver Olympic Games - Closing Ceremony</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>173</ID>
    <DoodleDate>2010-05-09</DoodleDate>
    <Doodle>J.M. Barrie's 150th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>175</ID>
    <DoodleDate>2010-05-09</DoodleDate>
    <Doodle>Mother's Day 2010 - USA</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>176</ID>
    <DoodleDate>2010-04-01</DoodleDate>
    <Doodle>April Fool's Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>177</ID>
    <DoodleDate>2010-06-14</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Taiwan Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>178</ID>
    <DoodleDate>2010-06-16</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Spain by Julia Egido Martínez</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>179</ID>
    <DoodleDate>2010-06-16</DoodleDate>
    <Doodle>Dragon Boat Festival 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>180</ID>
    <DoodleDate>2010-06-21</DoodleDate>
    <Doodle>First Day of Summer 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>181</ID>
    <DoodleDate>2010-06-21</DoodleDate>
    <Doodle>First Day of Winter 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>182</ID>
    <DoodleDate>2010-05-07</DoodleDate>
    <Doodle>Pyotr Ilyich Tchaikovsky's 170th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>184</ID>
    <DoodleDate>2010-02-28</DoodleDate>
    <Doodle>Lantern Festival 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>185</ID>
    <DoodleDate>2010-06-21</DoodleDate>
    <Doodle>Jean-Paul Sartre's 105th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>187</ID>
    <DoodleDate>2010-04-09</DoodleDate>
    <Doodle>Vlasta Burian's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>188</ID>
    <DoodleDate>2010-05-13</DoodleDate>
    <Doodle>Children's Day' (Sweden - SE)</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>189</ID>
    <DoodleDate>2010-05-14</DoodleDate>
    <Doodle>Paraguay Independence Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>190</ID>
    <DoodleDate>2010-05-13</DoodleDate>
    <Doodle>Father's Day 2010 - Multiple Countries on Various Dates</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>191</ID>
    <DoodleDate>2010-06-22</DoodleDate>
    <Doodle>Konrad Zuse's 100th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>193</ID>
    <DoodleDate>2010-04-15</DoodleDate>
    <Doodle>Children's Day 2010 - Multiple Countries on Various Dates</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>194</ID>
    <DoodleDate>2010-05-15</DoodleDate>
    <Doodle>Teachers' Day 2010 - Multiple Countries on Various Dates</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>195</ID>
    <DoodleDate>2010-05-14</DoodleDate>
    <Doodle>Singapore Art Festival 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>196</ID>
    <DoodleDate>2010-06-29</DoodleDate>
    <Doodle>Antoine de Saint-Exupery's 110th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>198</ID>
    <DoodleDate>2010-04-16</DoodleDate>
    <Doodle>Italian Culture Week</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>199</ID>
    <DoodleDate>2010-04-17</DoodleDate>
    <Doodle>Karen Blixen's 125th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>200</ID>
    <DoodleDate>2010-04-17</DoodleDate>
    <Doodle>Josif Pancic's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>201</ID>
    <DoodleDate>2010-06-26</DoodleDate>
    <Doodle>Sunthorn Phu's 224th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>202</ID>
    <DoodleDate>2010-04-22</DoodleDate>
    <Doodle>Earth Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>203</ID>
    <DoodleDate>2010-03-01</DoodleDate>
    <Doodle>Frederic Chopin's 200th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>204</ID>
    <DoodleDate>2010-03-02</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - Ireland Winner</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>205</ID>
    <DoodleDate>2010-03-03</DoodleDate>
    <Doodle>Girls Day 2010 - Japan</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>206</ID>
    <DoodleDate>2010-05-25</DoodleDate>
    <Doodle>Jordan National Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>207</ID>
    <DoodleDate>2010-04-20</DoodleDate>
    <Doodle>Independence Day Israel 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>208</ID>
    <DoodleDate>2010-05-21</DoodleDate>
    <Doodle>30th Anniversary of PAC-MAN</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>209</ID>
    <DoodleDate>2010-04-19</DoodleDate>
    <Doodle>Feria de Abril</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>210</ID>
    <DoodleDate>2010-05-17</DoodleDate>
    <Doodle>Martin Kukucin's 150th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>211</ID>
    <DoodleDate>2010-03-01</DoodleDate>
    <Doodle>St. David's Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>212</ID>
    <DoodleDate>2010-03-01</DoodleDate>
    <Doodle>Holi Festival 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>213</ID>
    <DoodleDate>2010-03-01</DoodleDate>
    <Doodle>Martisor 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>214</ID>
    <DoodleDate>2010-05-25</DoodleDate>
    <Doodle>Argentina's Bicentennial Independence</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>216</ID>
    <DoodleDate>2010-04-23</DoodleDate>
    <Doodle>National Sovereignty and Children's Day 2010 - Turkey</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>217</ID>
    <DoodleDate>2010-03-04</DoodleDate>
    <Doodle>Antonio Vivaldi's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>218</ID>
    <DoodleDate>2010-03-06</DoodleDate>
    <Doodle>Vasaloppet 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>219</ID>
    <DoodleDate>2010-04-23</DoodleDate>
    <Doodle>St. George's Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>220</ID>
    <DoodleDate>2010-03-03</DoodleDate>
    <Doodle>Election Day 2010 - Netherlands</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>221</ID>
    <DoodleDate>2010-03-07</DoodleDate>
    <Doodle>Alessandro Manzoni's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>222</ID>
    <DoodleDate>2010-03-12</DoodleDate>
    <Doodle>Arbor Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>223</ID>
    <DoodleDate>2010-03-14</DoodleDate>
    <Doodle>Felix Rodriguez de la Fuente's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>224</ID>
    <DoodleDate>2010-03-08</DoodleDate>
    <Doodle>Women's Day 2010 - Russian</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>225</ID>
    <DoodleDate>2010-05-29</DoodleDate>
    <Doodle>John Harsányi's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>226</ID>
    <DoodleDate>2010-04-25</DoodleDate>
    <Doodle>ANZAC Day 2010 - Australia</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>227</ID>
    <DoodleDate>2010-04-25</DoodleDate>
    <Doodle>ANZAC Day 2010 - New Zealand</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>228</ID>
    <DoodleDate>2010-03-13</DoodleDate>
    <Doodle>Holmenkollen Ski Festival 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>229</ID>
    <DoodleDate>2010-05-28</DoodleDate>
    <Doodle>Milutin Milankovich's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>230</ID>
    <DoodleDate>2010-05-29</DoodleDate>
    <Doodle>Isaac Albeniz's 150th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>231</ID>
    <DoodleDate>2010-05-27</DoodleDate>
    <Doodle>Doodle 4 Google 2010 - US by Makenzie Melton</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>232</ID>
    <DoodleDate>2010-04-24</DoodleDate>
    <Doodle>Hubble Space Telescope's 20th Anniversary</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>233</ID>
    <DoodleDate>2010-04-30</DoodleDate>
    <Doodle>Queen's Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>234</ID>
    <DoodleDate>2010-03-14</DoodleDate>
    <Doodle>Mother's Day 2010 - UK &amp; Ireland</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>235</ID>
    <DoodleDate>2010-04-29</DoodleDate>
    <Doodle>225th Birthday of Karl Drais</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>236</ID>
    <DoodleDate>2010-03-14</DoodleDate>
    <Doodle>Pi Day</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>237</ID>
    <DoodleDate>2010-03-15</DoodleDate>
    <Doodle>Hungarian National Day</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>238</ID>
    <DoodleDate>2010-03-23</DoodleDate>
    <Doodle>Akira Kurosawa's Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>239</ID>
    <DoodleDate>2010-03-17</DoodleDate>
    <Doodle>Happy St. Patrick's Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>240</ID>
    <DoodleDate>2010-03-20</DoodleDate>
    <Doodle>Persian New Year 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>241</ID>
    <DoodleDate>2010-03-28</DoodleDate>
    <Doodle>Jan Amos Komensky's 418th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>242</ID>
    <DoodleDate>2010-03-24</DoodleDate>
    <Doodle>44th Anniversary of the First Israeli TV Broadcast</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>243</ID>
    <DoodleDate>2010-01-01</DoodleDate>
    <Doodle>Happy New Year 2010!</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>244</ID>
    <DoodleDate>2010-01-04</DoodleDate>
    <Doodle>Sir Isaac Newton's 367th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>245</ID>
    <DoodleDate>2010-01-11</DoodleDate>
    <Doodle>Coming of Age Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>246</ID>
    <DoodleDate>2010-01-20</DoodleDate>
    <Doodle>Festival of San Sebastian</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>247</ID>
    <DoodleDate>2010-01-18</DoodleDate>
    <Doodle>Dr. Martin Luther King Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>248</ID>
    <DoodleDate>2010-01-15</DoodleDate>
    <Doodle>Istanbul 2010 European Capital of Culture</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>249</ID>
    <DoodleDate>2010-01-14</DoodleDate>
    <Doodle>Festival of Kites 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>250</ID>
    <DoodleDate>2010-01-14</DoodleDate>
    <Doodle>Celebration of Chinese Culture</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>251</ID>
    <DoodleDate>2010-01-09</DoodleDate>
    <Doodle>Karel Capek's 120th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>252</ID>
    <DoodleDate>2010-01-21</DoodleDate>
    <Doodle>Grandparent's Day 2010 - Poland</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>253</ID>
    <DoodleDate>2010-01-26</DoodleDate>
    <Doodle>Republic Day of India 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>254</ID>
    <DoodleDate>2010-01-22</DoodleDate>
    <Doodle>Porridge Day 2010</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>255</ID>
    <DoodleDate>2010-01-29</DoodleDate>
    <Doodle>Anton Chekhov's 150th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>256</ID>
    <DoodleDate>2010-01-23</DoodleDate>
    <Doodle>Django Reinhard's 100th Birthday</Doodle>
  </GoogleDoodles>
  <GoogleDoodles>
    <ID>257</ID>
    <DoodleDate>2010-01-31</DoodleDate>
    <Doodle>Tapati Rapa Nui Festival 2010</Doodle>
  </GoogleDoodles>
</dataroot>

My working XSLT script uses the Muenchian Method and does transpose. However, data does not align to month columns especially if month/day did not have a corresponding Doodle to commemorate country's historical figure or day event. I am thinking comma placeholders need to be used and then translated with translate() for non-missing data or dynamic params.

Also, multiple Doodles appeared for same distinct date (e.g., Frederic Chopin's 200th Birthday, St. David's Day 2010, Holi Festival 2010, Martisor 2010 on Mar 1 2010). Below script does not take the first item of the grouping. I tried many variations to conditionally use monthid key (not shown below).

XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output version="1.0" encoding="UTF-8" method="text" indent="yes" />
<xsl:strip-space elements="*"/>

<xsl:key name="monthid" match="GoogleDoodles" use="substring(DoodleDate, 6, 2)" />
<xsl:key name="dayid" match="GoogleDoodles" use="concat(substring(DoodleDate, 1, 4), substring(DoodleDate, 9, 2))" />

<xsl:template match="dataroot">
     <xsl:text>Year,Day,January,February,March,April,May,June,July,August,September,October,November,December&#xa;</xsl:text>
     <xsl:for-each select="GoogleDoodles[count(. | key('dayid', concat(substring(DoodleDate, 1, 4), substring(DoodleDate, 9, 2)))[1])=1]">
        <xsl:sort select="substring(DoodleDate, 1, 4)" order="ascending" data-type="number"/>
        <xsl:sort select="substring(DoodleDate, 9, 2)" order="ascending" data-type="number"/>

        <Year><xsl:value-of select="substring(DoodleDate, 1, 4)"/></Year><xsl:text>,</xsl:text>         
        <Day><xsl:value-of select="substring(DoodleDate, 9, 2)"/></Day><xsl:text>,</xsl:text>

        <xsl:for-each select="key('dayid', concat(substring(DoodleDate, 1, 4), substring(DoodleDate, 9, 2)))">
            <xsl:sort select="substring(DoodleDate, 6, 2)" order="ascending" data-type="number"/>

            <xsl:variable name="monthvar" select="substring(DoodleDate, 6, 2)"/>

            <xsl:if test="$monthvar=1"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=2"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=3"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=4"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=5"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=6"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=7"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=8"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=9"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=10"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=11"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>
            <xsl:if test="$monthvar=12"><xsl:value-of select="Doodle"/><xsl:text>,</xsl:text></xsl:if>

         </xsl:for-each>
         <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>

</xsl:template>

</xsl:stylesheet>

Desired output is CSV, comma separated values, with blanks for non-included dates.

Year,Day,January,February,March,April,May,June
2010,1,Happy New Year 2010!,,Frederic Chopin's 200th Birthday,April Fool's Day 2010,Labour Day 2010,
2010,2,,Doodle 4 Google 2010 - New Zealand Winner,Doodle 4 Google 2010 - Ireland Winner,Hans Christian Andersen's 205th Birthday,Mother's Day 2010 - Multiple Countries on Various Dates,Republic Day Italy 2010
2010,3,,Norman Rockwell's 106th Birthday - 1926 SEPS by Curtis Publishing,Girls Day 2010 - Japan,,,
2010,4,Sir Isaac Newton's 367th Birthday,,Antonio Vivaldi's Birthday,,Umm Kalthum's Birthday,
2010,5,,,,,Rocket Festival,Dennis Gabor´s 110th birthday - Holography support courtesy of th
2010,6,,Sami National Day 2010,Vasaloppet 2010,,U.K. Election Day,Sweden National Day 2010
2010,7,,,Alessandro Manzoni's Birthday,,Pyotr Ilyich Tchaikovsky's 170th Birthday,
2010,8,,,Women's Day 2010 - Russian,,,Robert Schumann's 200th Birthday
2010,9,Karel Capek's 120th Birthday,Natsume Soseki's Birthday,,Vlasta Burian's Birthday,J.M. Barrie's 150th Birthday,Argentina Independence Day / Doodle for Google 2010 - Winner
2010,10,,,,,,
...


回答1:


I would take a very different approach:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8" />

<xsl:key name="event-by-date" match="GoogleDoodles" use="DoodleDate" />

<xsl:template match="/dataroot">
    <xsl:text>Year,Day,January,February,March,April,May,June,July,August,September,October,November,December&#10;</xsl:text>
    <xsl:call-template name="generate-rows">
        <xsl:with-param name="year" select="substring(GoogleDoodles[1]/DoodleDate, 1, 4) " />
    </xsl:call-template>
</xsl:template>

<xsl:template name="generate-rows">
    <xsl:param name="year"/>
    <xsl:param name="day" select="1"/>
    <xsl:if test="$day &lt;= 31">
        <xsl:value-of select="$year"/>
        <xsl:text>,</xsl:text>
        <xsl:value-of select="$day"/>
        <xsl:call-template name="generate-cols">
            <xsl:with-param name="year" select="$year" />
            <xsl:with-param name="day" select="$day" />
        </xsl:call-template>
        <xsl:text>&#10;</xsl:text>
        <!-- recursive call --> 
        <xsl:call-template name="generate-rows">
            <xsl:with-param name="year" select="$year" />
            <xsl:with-param name="day" select="$day + 1" />
        </xsl:call-template>
    </xsl:if>
</xsl:template>

<xsl:template name="generate-cols">
    <xsl:param name="year"/>
    <xsl:param name="day"/>
    <xsl:param name="month"  select="1"/>
    <xsl:variable name="date">
        <xsl:value-of select="$year"/>
        <xsl:value-of select="format-number($month, '-00')"/>
        <xsl:value-of select="format-number($day, '-00')"/>
    </xsl:variable>
    <xsl:if test="$month &lt;= 12">
        <xsl:text>,</xsl:text>
        <xsl:value-of select="key('event-by-date', $date)/Doodle"/>
        <!-- recursive call -->
        <xsl:call-template name="generate-cols">
            <xsl:with-param name="year" select="$year" />
            <xsl:with-param name="day" select="$day" />
            <xsl:with-param name="month" select="$month + 1" />
        </xsl:call-template>
    </xsl:if>   
</xsl:template>

</xsl:stylesheet>

This assumes all data is from the same year. If not, add another template to iterate from the minimum to the maximum year in the given data.

Note that each cell contains the first event for that date, in document order.



来源:https://stackoverflow.com/questions/38707512/xml-to-csv-transpose-by-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!