grouping by child element

Subject: grouping by child element
From: "Keith" <keith@xxxxxxxxxxxxx>
Date: Mon, 16 Oct 2000 09:31:11 -0500
Hi listers
I am relatively new to xslt. I have ordered Michael Kay's book and have been
keeping up with list for the past couple of weeks.  Any help on this one
will be greatly appreciated!
I have a simple list of data coming from a stored proc.  I have a sort set
up based on user selection.
the xml looks like this (using soap request/response method)
<GetMerchantListResponse>
<Merchant merchID="some_number">
	<merchName>Some_name</merchName>
	<merchActive>boolean value</merchActive>
	<merchIsoID>ISO ID number</merchIsoID>
</Merchant>
</GetMerchantListResponse>
I have them sorted (initially) by merchIsoID.  What I need to do is group
them into tables based on this element.
This will therefore allow me to use the "add merchant" button's relationship
to the group's merchIsoID for each set.  I originally had this working when
all the values coming in where attributes.
Now they are attributes(merchID) and the rest are elements and I can't seem
to get it to group correctly.

Below is the xsl i am working with:
<xsl:template match="/">
		<xsl:apply-templates select="//SOAP-ENV:Fault"/>
		<xsl:apply-templates select="//GetMerchantListResponse">
		<xsl:sort select="//Merchant"/>
		</xsl:apply-templates>
	</xsl:template>


	<xsl:template match="GetMerchantListResponse">
			<center>
				<input type="button" name="Filter" value="Filter"
onclick="field=prompt('What field would you like to
filter?','');filter(field);" />
				<form name="AddMerchant" method="post" action="AddMerchant.htm">
				<input type="hidden" name="merchIsoID"><xsl:attribute
name="value"><xsl:value-of select="merchIsoID"/></xsl:attribute></input>
				<input type="submit" name="submit" value="Add Merchant"/>
				</form>
			</center>
			<p>
				<table  border="1" align="center">
					<tr>
							<xsl:if test="Merchant/@merchID">
							<th>
								<xsl:attribute name="id">merchID</xsl:attribute>
								<xsl:attribute name="onclick">changeSortOrder()</xsl:attribute>
								<xsl:attribute name="style">background-color="#cccccc";
cursor=hand</xsl:attribute>
								ID
							</th>
							</xsl:if>

							<xsl:if test="Merchant/merchName">
							<th>
								<xsl:attribute name="id">merchName</xsl:attribute>
								<xsl:attribute name="onclick">changeSortOrder()</xsl:attribute>
								<xsl:attribute name="style">background-color="#cccccc";
cursor=hand</xsl:attribute>
								Name
							</th>
							</xsl:if>

							<xsl:if test="Merchant/merchActive">
							<th>
								<xsl:attribute name="id">merchActive</xsl:attribute>
								<xsl:attribute name="onclick">changeSortOrder()</xsl:attribute>
								<xsl:attribute name="style">background-color="#cccccc";
cursor=hand</xsl:attribute>
								Active
							</th>
							</xsl:if>

							<xsl:if test="Merchant/merchIsoID">
							<th>
								<xsl:attribute name="id">merchIsoID</xsl:attribute>
								<xsl:attribute name="onclick">changeSortOrder()</xsl:attribute>
								<xsl:attribute name="style">background-color="#cccccc";
cursor=hand</xsl:attribute>
								ISO ID
							</th>
							</xsl:if>
				</tr>
					<xsl:apply-templates select="Merchant">
					<xsl:sort select="merchIsoID"/>
					</xsl:apply-templates>
			</table>
		</p>
	</xsl:template>

	<xsl:template match="Merchant">
		<xsl:for-each select=".">
			<tr>
				<td>
					<a><xsl:attribute
name="href">GetMerchantDetails.htm?merchID=<xsl:value-of
select="@merchID"/></xsl:attribute><xsl:value-of select="@merchID"/>
					</a>
				</td>
				<td>
					<xsl:value-of select="merchName"/>
				</td>
				<td>
					<xsl:choose>
						<xsl:when test="merchActive = '1'">Yes
						</xsl:when>
						<xsl:otherwise>No
						</xsl:otherwise>
					</xsl:choose>
				</td>
				<td>
					<a><xsl:attribute name="href">GetISODetails.htm?isoID=<xsl:value-of
select="merchIsoID"/></xsl:attribute><xsl:value-of select="merchIsoID"/></a>
				</td>
			</tr>
		</xsl:for-each>
	</xsl:template>
Thanks in advance for any input the gurus can give!



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread