This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: grouping by attribute


Hi Kiran,
try this:

<xsl:template match="Property" xmlns:def="com/xpegs/v2000Q3/HotelML">
         <table>
                 <xsl:for-each select="def:Amenity">
                         <tr><td><xsl:value-of select="@Code"/></td>
                               <td><xsl:value-of select="@Description"/></td>
                         </tr>
                 </xsl:for-each>
         </table>
</xsl:template>

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@seacomindia.com
>kiranab@hotmail.com
>
>
>  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]