[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Finding nester distinct items

Subject: Finding nester distinct items
From: "Craig Kattner" <CKattner@xxxxxxxxxxxxxx>
Date: Mon, 10 Mar 2003 13:26:48 -0600
xsl apply templates distinct
I have the following XML:

<products>
<product id="439" model="FD12H">
	<desc>text</desc>
	<product_fact id="5" name="Finish">
		<val>Ivory Decorative</val>
	</product_fact>
	<product_fact id="8" name="Hold">
		<val>no</val>
	</product_fact>
	<product_fact id="6" name="Pole">
		<val>SPST</val>
	</product_fact>
	<product_fact id="7" name="Time">
		<val>12 hours</val>
	</product_fact>
</product>
<product id="439" model="FD6H">
	<desc>text</desc>
	<product_fact id="5" name="Finish">
		<val>Ivory Decorative</val>
	</product_fact>
	<product_fact id="8" name="Hold">
		<val>no</val>
	</product_fact>
	<product_fact id="6" name="Pole">
		<val>SPST</val>
	</product_fact>
	<product_fact id="7" name="Time">
		<val>6 hours</val>
	</product_fact>
</product>
<product id="439" model="FD4H">
	<desc>text</desc>
	<product_fact id="5" name="Finish">
		<val>Ivory Decorative</val>
	</product_fact>
	<product_fact id="8" name="Hold">
		<val>no</val>
	</product_fact>
	<product_fact id="6" name="Pole">
		<val>SPDT</val>
	</product_fact>
	<product_fact id="7" name="Time">
		<val>4 hours</val>
	</product_fact>
</product>
</products>

What I need is to get a distinct list of Pole val's and then for each Pole a distinct list of Time val's. (I need to be able to recreate this http://www.intermatic.com/comind/fdff.htm).

The best I've come up with is:

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

<xsl:template match="/">
	<xsl:apply-templates select="//product" />
</xsl:template>

<xsl:template match="product">
	<xsl:apply-templates select="product_fact[@name='Pole']" mode="pole_values">
		<xsl:sort select="@name" />
		<xsl:sort select="val" />
	</xsl:apply-templates>	
</xsl:template>

<!-- get the unique pole values -->
<xsl:template match="product_fact" mode="pole_values">
	<xsl:for-each select="../product_fact[not(val=following::product_fact/val) and @name='Pole']">
		<xsl:value-of select="val" /><br />
		<xsl:apply-templates select="." mode="time_values" />
	</xsl:for-each>
</xsl:template>

<!-- get the unique time values per pole -->
<xsl:template match="product_fact" mode="time_values">
	<xsl:for-each select="../ancestor::*/product/product_fact[not(val=following::product_fact/val) and @name='Time']">
		<xsl:value-of select="." /><br />
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

What I want is:
SPST
	12 Hours
	6 Hours
SPDT
	4 Hours

What I get is:
SPST
	12 Hours
	6 Hours
	4 Hours
SPDT
	12 Hours
	6 Hours
	4 Hours

Using MSXML 4 SP 1 for this if it makes a difference.

Thanks,
Craig


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.