[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Combining xsl:keys


Subject: Re: [xsl] Combining xsl:keys
From: David Laurie <dlaurie@xxxxxxxxxxx>
Date: Wed, 26 Jan 2005 14:09:54 -0700

You wrote:

>Hi,

>I don't see any duplicates in your xml, maybe its just a small part of the 
real >xml? Or do you consider the 'Climate in Alberta' series as duplicates?
>I'll assume you mean with duplicates "maptitles that are stringwise
>indentical".


>With tke keys:
><xsl:key name="maps" match="part/chapters/mapunits/maps/maptitle"
>use="substring(., 1, 1)"/>
><xsl:key name="maps" match="part/chapters/mapunits/maps/maptitle" use="."/>

>...
><xsl:for-each select="key('maps', $firstletter)[generate-id(.) =
>generate-id(key('maps', .)[1])]">
><xsl:sort/>
><div class="mapTitle">
><a>
><xsl:value-of select="."/>
></a>
></div>
></xsl:for-each>
>...


>using the 'preceding' axis:

><xsl:value-of select="self::maptitle[not(.=preceding::maptitle)]"/>


>regards,
>--
>Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
>Veni, vidi, wiki (http://www.wikipedia.org)

Thanks for your response Joris but I am still stumped.

As you guessed the xml i included was just a snippet to show the general 
structure; I am trying to eliminate <maptitles> that are stringwise identical.

I tested both your solutions and neither works while retaining the current 
function (which I may not have explained fully and where I think the trouble 
is arising with respect to removing duplicates).

The stylesheet is designed to create an alphabetic sort that groups by the 
first letter and catches it as a heading for the corresponding titles. This 
requires the key to use substring function (same for the generate ID). Thus I 
can't change the select criteria for the main for-each loop without returning 
a nullset. Any changes to the match or select paths returns nothing; 
similarily adding a second key (either the example you suggest or <xsl:key 
name="maps" match="part/chapters/mapunits/maps/maptitle" 
use=".[not(.=preceding::part/chapters/mapunits/maps/maptitle)]"/>) produces 
nothing.

The other solution, not=preceding, will not work because the for-each that 
produces it calls the key function e.g. <xsl:for-each select="key('maps', 
$firstletter)"> which blocks me from removing the duplicates here as the key 
does not work as a valid path i.e. within the for-each, the select would have 
to be: <xsl:value-of select=".[not(.=preceding::key)]"/>.

I hope this clarifies the problem. If you have any further thoughts, I'd 
appreciate it.

Cheers,

Dave



xsl:

<xsl:key name="maps" match="part/chapters/mapunits/maps/maptitle" 
use="substring(., 1, 1)"/>

	<xsl:template match="body" mode="alpha-title">
		<xsl:for-each select="(part/chapters/mapunits/maps/maptitle)
[generate-id(.) =
generate-id(key('maps', substring(., 1, 1))[1])]">
			<xsl:sort select="."/>
			<xsl:variable name="firstletter" select="substring(., 1, 1)"/>
			<div class="alphaHeader">
				<xsl:value-of select="$firstletter"/>
			</div>
			<xsl:for-each select="key('maps', $firstletter)">

			<xsl:sort select="."/>
				<div class="mapTitle">
					<a title="{.}" href="#" 
onclick="window.open('../../Maps/{../../../@chap}/{../../@mapunitNumber}/{../@
mapNumber}/Normal/','mapWindow','width=700,height=525,directories=no,location=
no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,top=50,left=50
'); return false;">
						<!--<xsl:value-of select="self::node[not(.=preceding::maps)]"/>-->
						<xsl:value-of select="."/>
					</a>
				</div>
			</xsl:for-each>
		</xsl:for-each>
	</xsl:template>

xml:

<atlas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="S:\Atlas\XSD\atlasSchema.xsd">

	<body>
		<part number="1">
			<sectiontitle>Alberta's Geography</sectiontitle>
			<chapters chap="1">
				<chaptertitle>Alberta's Land, Climate and Resources</chaptertitle>
				<mapunits mapunitNumber="1">
					<maps mapNumber="1">
						<maptitle>Relief Features of Alberta</maptitle>
						<thumb>
							<image>ReliefFeaturesAlbertathumb.jpg</image>
						</thumb>
						<fullsize>
							<image>ReliefFeaturesAlberta.jpg</image>
							<width>1706</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<maps mapNumber="2">
						<maptitle>Physiography of Alberta</maptitle>
						<thumb>
							<image>PhysiographyofAlbertathumb.jpg</image>
						</thumb>
						<fullsize>
							<image>PhysiographyofAlberta.jpg</image>
							<width>2418</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<maps mapNumber="3">
						<maptitle>Land Resources in Alberta</maptitle>
						<thumb>
							<image>ClimateandLandResourcesthumb.jpg</image>
						</thumb>
						<fullsize>
							<image>ClimateandLandResources.jpg</image>
							<width>2144</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<maps mapNumber="4">
						<maptitle>Soils in Alberta</maptitle>
						<thumb>
							<image>ClimateandLandResourcesSoilsthumb.jpg</image>
						</thumb>
						<fullsize>
							<image>ClimateandLandResourcesSoils.jpg</image>
							<width>2221</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<div divNumber="1">
						<head>Physical Geography of Alberta </head>
						<paragraph>When viewed on a map, Alberta is slightly askew physically 
because it does not rise evenly from the east to the mountains in the west, 
nor does it fall uniformly from the high plains in the south to the northern 
boundary. It looks like a book or sheet of plywood with a warped upper surface 
that has been picked up by its southwest corner and propped on a pencil or a 
log so that it tilts to the northeast. The Rocky Mountains form the border in 
a southeast-northwest line from the United States border to about 53050'N. The 
highest point in the province is Mt. Columbia on the B.C.-Alberta border at 
the head of the Athabasca River, whose summit is 12,294 ft. above sea 
level.<note reference="1"/> The nearest approaches to sea level are at the 
point where the Slave River crosses into the Northwest Territories,<note 
reference="2"/> and about 20&#150;25 miles west-southwest of here, in a low 
hay and swamp meadow including what is identified on the map as St. Bruno 
Farm, both of which are below 600 ft.<note reference="3"/> The Slave River 
descends in a series of rapids from the Pelican to the gruesomely named Rapids 
of the Drowned. Lake Athabasca, which is drained to the north by the Slave 
River, is about 700 ft. above sea level.<note reference="4"/>
						</paragraph>
						<paragraph>Several remarkable rises appear in the landscape east of the 
Rocky Mountains. The Cypress Hills in the southeast rise nearly 2000 ft. above 
the surrounding terrain,<note reference="5"/> enough to have avoided being 
glaciated in their upper reaches.<note reference="6"/> This has resulted in an 
island of flora and fauna which is a mix of species found 150 miles west in 
the Rocky Mountains, and others which are unusual for such a northerly 
latitude.<note reference="7"/> The Swan Hills, south of Lesser Slave Lake, the 
Clear Hills, north of the Peace River and east of the British Columbia 
boundary, and the Caribou Mountains in the far north of the Province, all rise 
over 1500 ft. above their surroundings with peak elevations of about 4300 ft., 
3500 ft., and 3200 ft. respectively.<note reference="8"/>
						</paragraph>
						<paragraph>The Province extends geographically from 490 to 600 North, 
the equivalent of Paris to the southern part of the Shetland Islands, from 
Stuttgart to Oslo, or from Poltava to St. Petersburg. The climate is more akin 
to though more severe than the last of these three, sheltered from the 
moderating influence of the Pacific Ocean by 500 miles of mountainous terrain. 
</paragraph>
						<paragraph>The natural vegetation of the northern three quarters of 
Alberta is dominated by Aspen Poplar, which only in recent times has become an 
economically important resource. In its southern reaches, it occurs in 
association with grasses that creates what is termed a Parkland region. White 
spruce, lodgepole pine and jackpine occur in mixed stands on higher ground in 
the foothills and mountain regions and on most uplands of central and northern 
Alberta. Black spruce and sphagnum moss, both of which have also found recent 
economic uses, occupy lower lying and wet upland areas.<note reference="9"/>
						</paragraph>
						<paragraph>Grasslands occupy the southern quarter of the Province east 
of the mountains and foothills. Over fifty percent of the grasslands and Aspen 
Poplar Parkland and forest region south of an east-west line half way between 
Edmonton and Athabasca, and east of a curving north-south line from Barrhead 
to Gull Lake to Cochrane and Pincher Creek, have been brought under 
cultivation.<note reference="10"/> A similar pattern of clearing the Parkland 
began in the Grande Prairie and Peace River districts in the decade between 
1910 and 1920,<note reference="11"/> and continues today in one of the few 
areas left where a person can homestead. </paragraph>
						<paragraph>On the high prairie, or short grass prairie of Southern 
Alberta, a continual shortage of moisture<note reference="12"/> results in 
frequent soil drifting. This may occur in winter, as well as summer, if 
snowfall is not adequate to cover fields left barren after harvest or if 
Chinooks remove the snow cover. The only reliable sources of water are the 
rivers descending from the Rocky Mountains,<note reference="13"/> providing 
water for cattle and water for crop agriculture, the latter through extensive 
irrigation systems. </paragraph>
						<paragraph>The rivers of Alberta drain to the south, the east, and the 
north. The Milk River Basin eventually becomes a part of the 
Missouri-Mississippi and empties into the Gulf of Mexico. The Bow and 
Saskatchewan Basins join the Nelson River and empty into Hudson Bay. The 
Athabasca and Peace River Basins become part of the Slave and Mackenzie system 
and thereby reach the Arctic Ocean.<note reference="14"/>
						</paragraph>
						<noteTexts>
							<noteText id="1">1. <emphasis appearance="Italic">Atlas of 
Alberta</emphasis>, Plate 10&#150;11 (Edmonton: The University of Alberta, 
1969). </noteText>
							<noteText id="2">2. National Topographic System, 1:250,000 series, 
sheet 74M, 3rd ed., 1967. </noteText>
							<noteText id="3">3. Ibid., sheet 84P, 3rd ed., 1967. The area noted is 
about 73.5 sq. mi. along the Salt River and Brine Creek. </noteText>
							<noteText id="4">4. Ibid., sheet 74M, 3rd ed., 1967. </noteText>
							<noteText id="5">5. National Topographic System, 1:500,000 series, 
sheet 72NW(S 1/2)[&amp;]72SW(N 1/2), 6th ed., 1973. </noteText>
							<noteText id="6">6. <emphasis appearance="Italic">Atlas of 
Alberta</emphasis>, Plate 12. </noteText>
							<noteText id="7">7. Charles D. Bird, and Ian A.R.Halladay, The Cypress 
Hills, in W.R. Hardy, <emphasis appearance="Italic">Alberta: A Natural 
History</emphasis> (Edmonton: The Patrons, 1967), p. 120. </noteText>
							<noteText id="8">8. National Topographic System, 1:500,000 series, 
sheets 83NE, 5th ed., 1978; 84SW, 6th ed., 1973; 84NE, 5th ed., 1964. 
</noteText>
							<noteText id="9">9. <emphasis appearance="Italic">Atlas of 
Alberta</emphasis>, Plate 28&#150;29. </noteText>
							<noteText id="10">10. Ibid. </noteText>
							<noteText id="11">11. Howard Palmer and Tamara Palmer, <emphasis 
appearance="Italic">Alberta: A New History</emphasis> (Edmonton: Hurtig, 
1990), p. 150. </noteText>
							<noteText id="12">12. <emphasis appearance="Italic">Atlas of 
Alberta</emphasis>, Plate 19. </noteText>
							<noteText id="13">13. Robert Green, and Arleigh H. Laycock, Mountains 
and Plains, in Hardy, p. 87. </noteText>
						</noteTexts>
					</div>
					<textexcerpt/>
					<inserts/>
					<photographs/>
					<charts/>
				</mapunits>
				<mapunits mapunitNumber="2">
					<maps mapNumber="1">
						<maptitle>Climate in Alberta - Precipitation</maptitle>
						<thumb>
							<image>ClimateandLandResourcesPrecipitationthumb.jpg</image>
						</thumb>
						<fullsize>
							<image>ClimateandLandResourcesPrecipitation.jpg</image>
							<width>1044</width>
							<height>2000</height>
						</fullsize>
						<layers/>
					</maps>
					<maps mapNumber="2">
						<maptitle>Climate in Alberta - The Warmest Month</maptitle>
						<thumb>
							<image>ClimateandLandResourcesTemperatureinAlbertaWarmestMonththumb.jpg
</image>
						</thumb>
						<fullsize>
							<image>ClimateandLandResourcesTemperatureinAlbertaWarmestMonth.jpg</ima
ge>
							<width>1566</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<maps mapNumber="3">
						<maptitle>Climate in Alberta - The Coldest Month</maptitle>
						<thumb>
							<image>ClimateandLandResourcesTemperatureinAlbertaColdestthumb.jpg</ima
ge>
						</thumb>
						<fullsize>
							<image>ClimateandLandResourcesTemperatureinAlbertaColdestMonth.jpg</ima
ge>
							<width>1566</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<maps mapNumber="4">
						<maptitle>Climate in Alberta - The Mean Annual Snowfall</maptitle>
						<thumb>
							<image>ClimateandLandResourcesAnnualSnowfallthumb.jpg</image>
						</thumb>
						<fullsize>
							<image>ClimateandLandResourcesAnnualSnowfall.jpg</image>
							<width>1566</width>
							<height>3000</height>
						</fullsize>
						<layers/>
					</maps>
					<div divNumber="1">
						<head>Climate and Weather </head>
						<paragraph>Alberta's climate and weather affect the construction and 
operation of railways. Extreme temperatures, rain, snow, ice, winds and fog, 
alone or in combination, have caused great concern to, and incurred major 
expenditures of time, labour and money by the railway companies. </paragraph>
						<paragraph>The severity of the winter of 1906-07, the worst in a quarter 
of a century, proved difficult for railways, as intense cold and drifting snow 
hampered, and in some cases stopped, trains from carrying supplies to 
communities, thus imposing hardship on everyone. Even in the spring it took a 
Canadian Northern train 18 days to travel from Winnipeg to Edmonton.<note 
reference="1"/> In 1951 a passenger train was almost buried by snow at 
Oyen.<note reference="2"/>
						</paragraph>
						<paragraph>In 1935 torrential rains, melting snow and gale force winds 
caused flooding along the south shore of Lesser Slave Lake causing extensive 
damage to the track of the Northern Alberta Railways.<note reference="3"/> 
Further along the line mudslides occurred at East Smoky Hill, and the bridge 
approaches at the Smoky River were partially washed away.<note reference="4"/>
						</paragraph>
						<paragraph>Blowing sand posed a problem for the Grand Trunk Pacific's 
line running on the east side of Br&#65533;ake.<note reference="5"/>
						</paragraph>
						<paragraph>Alberta's changing weather and other instances of the adverse 
impact of climate on railway operations remind railway companies to be ever 
vigilant. </paragraph>
						<noteTexts>
							<noteText id="1">1. <emphasis appearance="Italic">Canadian Annual 
Review</emphasis>, 1907, p. 141. </noteText>
							<noteText id="2">2. Canadian National Railways, Annual Report, 1951. 
</noteText>
							<noteText id="3">3. Ena Schneider, <emphasis 
appearance="Italic">Ribbons of Steel</emphasis> (Calgary: Detselig, 1989), p. 
159. </noteText>
							<noteText id="4">4. Ibid., p. 166. </noteText>
							<noteText id="5">5. H.A. Parker, Report on the Mountain Section, GTP. 
July, 1909, p. 18.31; The Energy Question, Energy Options, Ottawa. 
</noteText>
						</noteTexts>
					</div>
					<textexcerpt/>
					<inserts/>
					<photographs/>
					<charts/>
				</mapunits>
				<mapunits mapunitNumber="3">
					<maps mapNumber="1">
						<maptitle>Coal Areas of Alberta</maptitle>
						<thumb>
							<image>CoalAreasofAlbertathumb.jpg</image>
						</thumb>
						<fullsize>
							<image>CoalAreasofAlberta.jpg</image>
							<width>2414</width>
							<height>3000</height>
						</fullsize>
						<layers/>
						<excerpt>
							<head>Description of Coal Commonly Found in Alberta</head>
							<paragraph/>
						</excerpt>
						<graphicexcerpt>
							<graphictitle>Coal Industry Employment and Mines in 
Operation</graphictitle>
							<image>Coal Industry Employment and Mines in Operation</image>
							<width>1535</width>
							<height>3000</height>
						</graphicexcerpt>
						<graphicexcerpt>
							<graphictitle>Tons of Mined Coal in Alberta</graphictitle>
							<image>TonsofMinedCoalinAlberta.jpg</image>
							<width>1393</width>
							<height>3000</height>
						</graphicexcerpt>
					</maps>
					<div divNumber="1">
						<head>Railways and the Coal Mining Industry </head>
						<paragraph>By 1898 coal had become the chief source of energy for 
transportation, industry, domestic heating and electricity in Canada.<note 
reference="1"/>
						</paragraph>
						<paragraph>The development of a commercially important coal mining 
industry had to await the coming of the railways, which became a major user of 
coal and the sole means of its transport to market. As A.A. den Otter states:
The most obvious effect the railways had on the coal mining industry of the 
northwest was in determining the place and pace of its development.<note 
reference="2"/>
						</paragraph>
						<paragraph>The coal mining industry in Alberta never reached its full 
potential. High transportation costs meant that the distribution of coal was 
limited to the regional market of the prairie provinces.<note reference="3"/> 
Alberta coal was prevented from supplying the industrial heartland of Canada 
(i.e., Ontario) because of the easily available and less expensive 
Pennsylvania coal from the United States.<note reference="4"/> Canada's 
federal government was indifferent to establishing a national fuel policy that 
would have included meaningful subsidies and competitive freight rates for the 
transport of coal from the west to eastern consumers.<note reference="5"/> 
Some attempts were made to penetrate the Ontario market but without 
success.<note reference="6"/> The growth potential of Alberta was also 
affected by tariffs that prevented expansion into the United States, and by 
the lack of industries locating in the vicinity of the coal mines rendering 
the latter subservient to the railways, and the seasonal fluctuations of an 
agricultural economy.<note reference="7"/>
						</paragraph>
						<paragraph>It was after 1896, with the expansion of the railway network 
and the growth of population on the prairies, that the coal industry grew to 
satisfy the need for thefuel. </paragraph>
						<paragraph>In 1898 the CPR built through the Crownest Pass in order to 
reach the mineral resources of the Kootenay region in south-eastern British 
Columbia, which prompted the development of coal mining, especially on the 
Alberta side of the pass. This created traffic. Eventually, Crowsnest and 
Canmore coal supplanted Lethbridge coal for use in locomotives.<note 
reference="8"/> The CPR also opened and operated a mine at Bankhead (Banff) in 
1903. </paragraph>
						<paragraph>The Canadian Northern stimulated the expansion of coal mining 
around Drumheller when it built a branch line from its main line at Vegreville 
to Calgary. In partnership with the German Development Company coal deposits 
in the Brazeau were developed, thereby providing the Canadian Northern with an 
excellent steam coal for its locomotives and lessening its dependence on 
Pennsylvania coal. A branch line was built from Warden to Nordegg. A mine was 
also developed at Br&#65533;n the main line west of Yellowhead Pass. 
</paragraph>
						<paragraph>The Grand Trunk Pacific (a Grand Trunk Railway subsidiary) 
was the western leg of a new transcontinental railway, the result of the 
liberal government's inability to design a rational railway policy. The GTPR 
chose to use the Yellowhead Pass and was instrumental in opening the area 
south of its main line at Bickerdike, which came to be known as the Coal 
Branch. A mining operation was also established at Pocahontas near Jasper. 
</paragraph>
						<paragraph>Though talking about the CPR, den Otter's words could equally 
apply to the other two systems.<note reference="9"/>
						</paragraph>
						<paragraph>(their) impact on the general state of this industry was 
substantial. By their decision about the timing and location of main and 
branch lines, company officials decreed when and where mines would open, and 
their subsequent purchasing policies influenced the continued welfare of this 
industry&#133;Without the mines of western Canada, the railway would have to 
pay more for its fuel; without the railway, the mining industry would 
collapse.<note reference="10"/>
						</paragraph>
						<paragraph>As early as 1925 Canadian National Railways had been 
experimenting with diesel-electric locomotion, though coal and oil fired steam 
engines remained the primary motive power. A drastic change came in 1952 with 
the acquisition of over 100 diesel-electric units and by 1960 the steam era 
had come to an end.<note reference="11"/> Similarly in the same years the 
Canadian Pacific had completely switched to the new motive power, a process 
that had commenced in 1937.<note reference="12"/> Oil and gas became the 
preferred fuels for industry and domestic use. The coal industry was 
devastated, and the Alberta landscape dotted with ghost towns. </paragraph>
						<noteTexts>
							<noteText id="1">1. <emphasis appearance="Italic">Atlas of 
Alberta</emphasis>, 1969, Plate 26, and <emphasis appearance="Italic">The 
Canadian Encyclopedia</emphasis>, 2nd ed. (Edmonton: Hurtig, 1988), p. 51. 
</noteText>
							<noteText id="2">2. The Energy Question, Energy Options, Ottawa. 
</noteText>
							<noteText id="3">3. A.A. den Otter, Bondage of Steam in the CPR West 
in Hugh Dempsey, ed., <emphasis appearance="Italic">The CPR West: The Iron 
Road the Making of a Nation</emphasis> (Vancouver: Douglas and MacIntyre, 
1984), p. 193. </noteText>
							<noteText id="4">4. A.A. den Otter, Railways and Alberta's Coal 
Problem, 1860&#150;1960 in A.W. Rasporich, ed., <emphasis 
appearance="Italic">Western Canada Past and Present</emphasis> (Calgary: 
University of Calgary/McClelland and Stewart, 1975), p. 86. </noteText>
							<noteText id="5">5. den Otter, Bondage of Steam, p. 193. </noteText>
							<noteText id="6">6. Royal Commission on the Coal Industry of Canada, 
Alberta Submission, 1945, pp. R&#150;1, P&#150;2. </noteText>
							<noteText id="7">7. den Otter, Railways and Alberta's Coal Problem, 
p. 92&#150;93. </noteText>
							<noteText id="8">8. den Otter, Bondage of Steam, pp. 200, 202; C.A. 
Seager, A Proletarian in Wild Rose Country (Ph.D. dissertation, Department 
of History, York University, 1981), p. 21. </noteText>
							<noteText id="9">9. R.G. Seale, Some Geographical Aspects of the Coal 
Industry in Alberta (Thesis, Department of Geography, University of Alberta, 
1966), p. 39. </noteText>
							<noteText id="10">10. den Otter, Bondage of Steam, p. 199. 
</noteText>
							<noteText id="11">11. A. Glegg and R. Corley, <emphasis 
appearance="Italic">Canadian National Steam Power</emphasis> (Montreal: 
Railfare Enterprises, 1969), p. 52. </noteText>
							<noteText id="12">12. M.W. Dean and D.B. Hanna, <emphasis 
appearance="Italic">Canadian Pacific Diesel Locomotives</emphasis> (Toronto: A 
Railfare Enterprises, 1981), p. 9. Omer Lavall&#35040;points out that as far 
back as 1912 conversion to oil burning locomotives was undertaken not (for) 
fuel economy but rather the easing of physical strains on fireman.&#133;The 
subsequent introduciton of mechanical stokers regained popularity for 
coal-burning locomotives. The oil burners were concentrated between Field and 
Revelstoke. Omar Lavallie Canadian Pacific Steam Locomotives (Toronto: A 
Railfare Enterprises, 1985), p. 130. </noteText>
						</noteTexts>
					</div>
					<textexcerpt/>
					<inserts/>
					<photographs/>
					<charts/>
				</mapunits>
			</chapters>
		</part>
</body>
</atlas>

David Laurie
MA Humanities Computing


Current Thread
Keywords
xml