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

RE: Grouping using the set:Distinct template from EXSL

Subject: RE: Grouping using the set:Distinct template from EXSLT
From: "Vandna Sharma" <sharmav@xxxxxxxxxxxxx>
Date: Tue, 17 Apr 2007 11:51:00 -0400
 RE: Grouping using the set:Distinct template from EXSL
> Hi all I am very new to XSLT programming,
> I am trying to do, "Grouping using the set:Distinct template from EXSLT". I
am having problem when I try to debug the xml file, I am getting error message
undefined template. I am using XMLspy version 5 rel.4. Below is the xml file,
and xsl.
>
XSL file

> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:set="http://exslt.org/set" version="1.0"
extension-element-prefixes="set" set:doc="http://www.exslt.org/set">
>     <xsl:output encoding="utf-8" method="html" />
>     <xsl:include href="style1.xsl"/>
>
> 	<!--  The essence of using the variable instead is very similar to a key
table.  In
> 	this solution, all products are put into the variable (which itself is in
document order):-->
>     <xsl:variable name="AllProducts" select="/"/>
>
> 	<!-- The variable $AllRegions will be initialized with all of the distinct
> 	     region elements.  This collection of nodes is created using the
> 	     set:distinct extension function from EXSLT.org (see bottom) -->
>     <xsl:variable name="AllRegionsDistinct">
>     	   <xsl:call-template name="set:distinct">
>          	  <xsl:with-param name="nodes" select="//products/product/region"
/>
>         </xsl:call-template>
> 	</xsl:variable>
> 	<xsl:variable name="AllRegions" select="$AllRegionsDistinct"/>
>
>
> 	<!-- Template for root rule -->
>     <xsl:template match="/">
> 	    	<xsl:call-template name="Style1"/>
> 		<h2>Grouping of Products by Region, then by Product Name </h2>
>      	<xsl:apply-templates />
>     </xsl:template>
>
> 	<!-- Template for products rule -->
>     <xsl:template match="products">
>
> 		<!-- Iterate through the variable containing all of the unique regions
-->
> 	    <xsl:for-each select="$AllRegions/region">
> 	    	<xsl:variable name="region" select="." /><BR></BR>
>
> 		    <H3>Region:    <xsl:value-of select="$region" /></H3>
>
>     		<table border="1">
>     			<tr>
>     			<th>Product ID</th>
> 			    <th>Name</th>
> 			    <th>Price</th>
> 		 	    <th>Quantity</th>
> 		 	    <th>Region</th>
>        			</tr>
>
> 			<!-- Grab the product elements that match the current retion.  At this
point
> 			     the products are retrived from our variable rather than the document
itself-->
>     		<xsl:for-each select="$AllProducts/products/product[region=$region]">
>     			<xsl:sort select="name"/>
>     			<tr>
>     			<td><xsl:value-of select="prodid" /></td>
> 			    <td><xsl:value-of select="name" /></td>
> 			    <td><xsl:value-of select="price" /></td>
> 		 	    <td><xsl:value-of select="quantity" /></td>
> 		 	    <td><xsl:value-of select="region" /></td>
>
>        			</tr>
>     		</xsl:for-each>
>     		</table>
>     	</xsl:for-each>
>     </xsl:template>
>
>     <xsl:template name="set:distinct">
>         <xsl:param name="nodes" select="/.." />
>
>         <xsl:choose>
>             <xsl:when test="not($nodes)" />
>
>             <xsl:otherwise>
>                 <xsl:copy-of select="$nodes[1][not(. = $nodes[position()
&gt; 1])]" />
>
>                 <xsl:call-template name="set:distinct">
>                     <xsl:with-param name="nodes" select="$nodes[position()
&gt; 1]" />
>                 </xsl:call-template>
>             </xsl:otherwise>
>         </xsl:choose>
>     </xsl:template>
> </xsl:stylesheet>
>
>
>
>
>
> XML file
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <products>
> 	<product>
> 		<prodid>V123049</prodid>
> 		<name>Screen-Top Monitor Shelf</name>
> 		<price>$59</price>
> 		<quantity>30</quantity>
> 		<region>NorthWest</region>
> 	</product>
> 	<product>
> 		<prodid>V392039</prodid>
> 		<name>Womens Bracelet Watch</name>
> 		<price>$175</price>
> 		<quantity>335</quantity>
> 		<region>SouthWest</region>
> 	</product>
> 	<product>
> 		<prodid>L930389</prodid>
> 		<name>Tobshiba Portable DVD Player</name>
> 		<price>$1,299</price>
> 		<quantity> >30</quantity>
> 		<region>NorthWest</region>
> 	</product>
> </products>
>
>
>
>
>
> Thanks
> Vandna

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.