[thelist] 'Banded' reports in xslt

Dave Merrill dmerrill at usa.net
Wed Dec 28 10:03:04 CST 2005


Hello, new to xslt here...

I have data that's conceptually like this:
-----------------------
<states>
	<state name="AK">
		<cities>
			<city name="Gnome"/>
			<city name="Fairbanks"/>
		</cities>
	</state>
	<state name="CO">
		<cities>
			<city name="Denver"/>
			<city name="Aspen"/>
			<city name="Boulder"/>
		</cities>
	</state>
</states>
-----------------------

Here's a simple xsl template that displays an h3 header for each state, then
lists the cities within that state.
-----------------------
<xsl:template match="/">
	<xsl:for-each select="/states/state">
		<xsl:variable name="thisState" select='@name'/>
		<h3><xsl:value-of select="@name"/></h3>
		<xsl:for-each select="//cities[../@name=$thisState]/city">
<xsl:value-of select="@name"/><br/>
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>
-----------------------

It works fine. The question, newb and explorer that I am, is whether setting
a variable is the only (or best) way to do this kind of second-level
filtering. Is there any construct that directly refers to the value of an
attribute in a higher level for-each loop?

Thanks very much,

Dave Merrill





More information about the thelist mailing list