Re: [xsl] grouping by attribute

Subject: Re: [xsl] grouping by attribute
From: Manu KY <manu_kry@xxxxxxxxx>
Date: Wed, 10 Oct 2001 13:01:20 +0530
Hi,
sorry for the code , its a little different than what you want...

try this instead:

<xsl:template match="/def:Property" xmlns:def="com/xpegs/v2000Q3/HotelML">
        <table>
            <xsl:call-template name="generate"/>
        </table>
</xsl:template>

<xsl:template name="generate" xmlns:def="com/xpegs/v2000Q3/HotelML">
<xsl:param name="counter" select="1"/>
<tr>
<td><xsl:value-of select="def:Amenity[$counter]/@Description"/></td>
<td><xsl:value-of select="def:Amenity[$counter+1]/@Description"/></td>
<td><xsl:value-of select="def:Amenity[$counter+2]/@Description"/></td>
</tr>


        <xsl:if test="$counter &lt; 7">
            <xsl:call-template name="generate" >
                <xsl:with-param name="counter" select="$counter+3"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

i have used counter for this and it counts only for 3 groups.
you could add a variable to check for the maximum number of groups you want accordingly .



really sorry for the wrong code!!!!


Manu

HI,

My XML code has a following pattern:

<?xml version="1.0"?>

<Property xmlns="com/xpegs/v2000Q3/HotelML" Name="Pride Hotel"
Code="UI;29966" Token="979242313749">

<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="ROOM24" Description="24
Hour Room Service"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="HAIR"
Description="Hairdryer in Room"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="TEL"
Description="Telephone"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="LOUNGE"
Description="Lounge"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="TVCAB"
Description="Television with Cable"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="TMPCTL"
Description="Temperature Control"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="HEALTH"
Description="Health Club"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="REST"
Description="Restaurant"/>
<Amenity xmlns="com/xpegs/v2000Q3/HotelML" Code="BELL"
Description="Porters"/>


</Property>


My XSL output is expected to be: <table> <tr> <td>24 Hour Room Service</td> <td>Hairdryer in Room</td> <td>Telephone</td> </tr>

<tr>
<td>Lounge</td>
<td>Television with Cable</td>
<td>Temperature Control</td>
</tr>

<tr>
<td>Health Club</td>
<td>Restaurant</td>
<td>Porters</td>
</tr>
<table>

I have tried the following options as given in your XSL FAQ section
(http://www.dpawson.co.uk/xsl/sect2/N4486.html#d137e42)
but none of them works......:(:(:(:(

<xsl:template match="/">
        <html>



1.              <table width="373" cellspacing="0" cellpadding="0" border="1"
bordercolor="#BCBCBC">

<xsl:for-each select="Property">

<tr>

<td>

<xsl:for-each
select="{Amenity@Description}[count(preceding-sibling::Amenity[1] |
current()) = 1]">

<xsl:value-of select="Amenity@Description"/>,

</xsl:for-each>

</td>

</tr>

</xsl:for-each>

</table>




2. <table width="373" cellspacing="0" cellpadding="0" border="1" bordercolor="#BCBCBC">

<xsl:for-each select="Property/Amenity">

<xsl:template match="{@Description}[position() mod 3 = 1]"
priority="2">

<tr>

<td><xsl:value-of select="." mode="1"/></td>

<td><xsl:value-of
select="following-sibling::{@Description}[1]"/></td>

<td><xsl:value-of
select="following-sibling::{@Description}[2]"/></td>

</tr>

</xsl:template>

</xsl:for-each>

</table>




3. <table width="373" cellspacing="0" cellpadding="0" border="1" bordercolor="#BCBCBC">

<xsl:for-each select="Property">

<xsl:call-template name="triples">

<xsl:with-param name="nodes" select="Amenity"/>

</xsl:call-template>

</xsl:for-each>


<xsl:param name="max" select="number(3)"/>


</table>




4. <table width="373" cellspacing="0" cellpadding="0" border="1" bordercolor="#BCBCBC">

<xsl:template match="Property">

<tr>

<xsl:for-each select="Amenity">

<td><xsl:apply-templates/></td>

<xsl:if test="position() mod $max = 0 and
position()!=last()">

<xsl:text
disable-output-escaping="yes"><![CDATA[</tr><tr>]]></xsl:text>

</xsl:if>

</xsl:for-each>

</tr>

</xsl:template>

</table>




5. <table width="373" cellspacing="0" cellpadding="0" border="1" bordercolor="#BCBCBC">

<xsl:template match="Property">

<xsl:for-each select="Amenity[position() mod $max = 1]" >

<tr>

<xsl:for-each select="self::Amenity |
following-sibling::Amenity[position() = $max]">

<td><xsl:apply-templates/></td>

</xsl:for-each>

</tr>

</xsl:for-each>

</xsl:template>
                                        </table>


</html> </xsl:template>




Please guide me regarding this.....!!


Also I want to know, what difference does it make to use either of the
following statements, on the execution of the rest of the code in XSL.
I could see the solution for grouping 3 items (as I want it) in FAQ section,
but that code does not work when I use the 1st sentence from the following
statements. Plzz
guide me regarding this too.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl";>

or

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


Thanx and Regards Ms. Kiran Bhide Seacom Solutions (India) Ltd. kiran@xxxxxxxxxxxxxxx kiranab@xxxxxxxxxxx


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


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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



Current Thread