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

Re: [xsl] Compound filter in for-each


Subject: Re: [xsl] Compound filter in for-each
From: "Alan Hale" <A.Hale@xxxxxxxxxx>
Date: Fri, 27 Mar 2009 09:22:55 +0000

>>> Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> 22:16 26 March 2009 >>>
Alan,

At 04:44 PM 3/26/2009, you wrote:
>Out of interest (and to facilitate further understanding) would you
>be kind enough to illustrate how you would approach my filtering
>problem with template matching rather than with xsl:choose?

It's likely that you could inspire a small friendly competition along
those lines, but might you post a small sample of input data, with a
prose spec and/or sample of desired results, to encourage those who
might be inclined to try their hand?

*----------------------------------------------------------------------------
------------------------------

OK, I think I have worked this out (and in the process have gained more
understanding of what you and Michael have been trying to explain).

To re-state: My XML (derived from KML) looks basically like this (some
editing):

<?xml version="1.0" encoding="UTF-8"?>
<kml>
  <Document>
	<Folder>
		<name>Acer campestre</name>
		<Placemark id="rpr_1">
			<name>Acer campestre</name>
			<ExtendedData>
			                 <Data name="grid_ref">
					<value>SN593798</value>
				</Data>
				<Data name="eng_name">
					<value>Field Maple</value>
				</Data>
				<Data name="rdb_status">
					<value>Lower risk - least
concern</value>
				</Data>
				<Data name="location_name">
					<value>Penparcau</value>
				</Data>
				<Data name="last_seen">
					<value>**/**/2000</value>
				</Data>
			</ExtendedData>
			<Point>
				<coordinates>-4.069436,52.398051,0</coordinates>
			</Point>
		</Placemark>
	</Folder>
</Document>
</kml>

<Folder> and <Placemark> are repeated

I want to display (in csv format) the values of certain child nodes of
<Placemark> but (and this was the issue) in certain circumstances I
want to select out only data from Placemarks where <Data name
='rdb_status'> and <Data/value='Endangered'>.

So, this is my solution now (avoiding using xsl:choose):

	<xsl:template match="Folder">
			<xsl:for-each
select="Placemark[ExtendedData/Data/attribute::name='rdb_status' and
ExtendedData/Data/value='Endangered']">
			<xsl:value-of select="@id" />,
			<xsl:value-of select="name" />,
			<xsl:value-of
select="ExtendedData/Data[@name='location_name']/value"/>,
			<xsl:value-of
select="ExtendedData/Data[@name='grid_ref']/value"/>,
			<xsl:value-of
select="ExtendedData/Data[@name='rdb_status']/value"/>,
			<xsl:value-of
select="ExtendedData/Data[@name='last_seen']/value"/>,
			<br/>
			</xsl:for-each>
	</xsl:template>


the <xsl:for-each> element being the most significant in the context of
this problem.

(Getting the syntax correct for the Data@name attribute threw me at
first).

This is probably trivial for many but I big leap forward in
understanding for me. Thanks again.

Alan Hale
Aberystwyth


Current Thread
Keywords
xml