[xsl] Can I group 3 levels somehow

Subject: [xsl] Can I group 3 levels somehow
From: "gary cor" <stuff4gary@xxxxxxxxxxx>
Date: Thu, 21 Mar 2002 20:17:17
Dear all,

My XML is...

I am trying to group xml elements using three attributes.

i.e.

- Firstly, I want to group them by the imagetype

---- Then within these imagetype groups, group by ordinal

---------- then within imagetype and ordinal I want to groupby imageparentid

Is this possible can anyone help.

Many thanks in advance

G.

PS Files follow below

<?xml version="1.0" encoding="utf-8"?>
<article>
<images>
<image ordinal="1" imgsrc="/upload_images/sony_printer_dscs85-146.jpg" imagex="146" imagey="129" alt="Some techy equipment" imagesize="articlethird" caption="Picture 4 caption here" bytesize="5947" imageparentid="" imagetype="article" imageid="13224" />
<image ordinal="2" imgsrc="/upload_images/psp7-146.jpg" imagex="146" imagey="110" alt="screen grabber" imagesize="articlethird" caption="This is a silly picture number 2" bytesize="7276" imageparentid="" imagetype="article" imageid="13222" />
<image ordinal="1" imgsrc="/upload_images/Sample-1462.jpg" imagex="146" imagey="109" alt="Someone about to sprint" imagesize="articlethird" caption="sport picture image 3" bytesize="3911" imageparentid="" imagetype="gallery" imageid="13223" />
<image ordinal="1" imgsrc="/upload_images/Sample-146.jpg" imagex="146" imagey="109" alt="alt tag image 1" imagesize="articlethird" caption="caption for picture 1" bytesize="3911" imageparentid="13223" imagetype="gallery" imageid="13225" />
<image ordinal="2" imgsrc="/upload_images/psp7-1462.jpg" imagex="146" imagey="110" alt="alt6" imagesize="articlethird" caption="capt6" bytesize="7276" imageparentid="" imagetype="gallery" imageid="13260" />
<image ordinal="2" imgsrc="/upload_images/Sample-1461.jpg" imagex="146" imagey="109" alt="alt7" imagesize="articlethird" caption="caption7" bytesize="3911" imageparentid="13260" imagetype="gallery" imageid="13261" />
<image ordinal="3" imgsrc="/upload_images/psp7-146.jpg" imagex="146" imagey="110" alt="alt3" imagesize="articlethird" caption="caption3" bytesize="7276" imageparentid="13223" imagetype="gallery" imageid="13257" />
<image ordinal="4" imgsrc="/upload_images/psp7-1461.jpg" imagex="146" imagey="110" alt="alt4" imagesize="articlethird" caption="caption4" bytesize="7276" imageparentid="" imagetype="gallery" imageid="13258" />
<image ordinal="5" imgsrc="/upload_images/sony_printer_dscs85-146.jpg" imagex="146" imagey="129" alt="alt5" imagesize="articlethird" caption="caption5" bytesize="5947" imageparentid="" imagetype="gallery" imageid="13259" />
<image ordinal="1" imgsrc="/upload_images/dummy_thumbnail.jpg" imagex="60" imagey="60" alt="I'm the alt tag" imagesize="smallthumbnail" caption="" bytesize="" imageparentid="" imagetype="index" imageid="13209" />
</images>
</article>


My XSLT so far is

<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:output method="html"/>

<xsl:param name="im-type"/>
<xsl:key name="images-by-type" match="image" use="@imagetype" />
<xsl:key name="images-by-type2" match="image" use="@ordinal" />

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

<xsl:template match="images">

<h2>Grouping of Products by various attributes</h2>
<xsl:for-each select="image[generate-id(.)=generate-id(key('images-by-type',@imagetype))]">
<xsl:sort select="@ordinal" order="ascending"/>
<h2>
<xsl:text>Image Type -</xsl:text><xsl:value-of select="@imagetype"/>
</h2>
<table border="1">
<tr>
<th>Ordinals</th>
<th>imgsrc</th>
<th>imagex</th>
<th>imagey</th>
<th>alt</th>
<th>imagesize</th>
<th>bytesize</th>
<th>imageparentid</th>
<th>imagetype</th>
<th>imageid</th>
</tr>


	<xsl:for-each select="key('images-by-type',@imagetype)">
	<xsl:sort select="@ordinal"/>
         <tr>
           <td>
             <xsl:value-of select="@ordinal" />
           </td>
           <td>
             <xsl:value-of select="@imgsrc" />
           </td>
           <td>
             <xsl:value-of select="@imagex" />
           </td>
           <td>
             <xsl:value-of select="@imagey" />
           </td>
           <td>
             <xsl:value-of select="@alt" />
           </td>
           <td>
             <xsl:value-of select="@imagesize" />
           </td>
           <td>
             <xsl:value-of select="@bytesize" />
           </td>
           <td>
             <xsl:value-of select="@imageparentid" />
           </td>
           <td>
             <xsl:value-of select="@imagetype" />
           </td>
           <td>
             <xsl:value-of select="@imageid" />
           </td>
         </tr>
         <!--

			<xsl:for-each select="key('images-by-type',@imagetype)">
			<xsl:sort select="imageparentid"/>
         <tr>
           <td>
             <xsl:value-of select="@ordinal" />
           </td>
           <td>
             <xsl:value-of select="@imgsrc" />
           </td>
           <td>
             <xsl:value-of select="@imagex" />
           </td>
           <td>
             <xsl:value-of select="@imagey" />
           </td>
           <td>
             <xsl:value-of select="@alt" />
           </td>
           <td>
             <xsl:value-of select="@imagesize" />
           </td>
           <td>
             <xsl:value-of select="@bytesize" />
           </td>
           <td>
             <xsl:value-of select="@imageparentid" />
           </td>
           <td>
             <xsl:value-of select="@imagetype" />
           </td>
           <td>
             <xsl:value-of select="@imageid" />
           </td>
         </tr>
			</xsl:for-each>-->


</xsl:for-each> </table> <br /> <br /> </xsl:for-each>

</xsl:template>


</xsl:stylesheet>


_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com



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



Current Thread