Enzero
Enzero

Reputation: 1141

XSL Group by Item Model

My problem is that I want to group by model for each item but I only want to load the details of single entity

<Search-Request search-term="1 tb">
    <Items>
        <Item href="SEA1TBST31000524AS.jpg" model="ST31000524AS">
            <Name>Seagate Hard disk 1TB ST31000524AS 3.5"</Name>
            <Price>60.50</Price>
            <SupplierCode>TECSEA1TB</SupplierCode>
            <Supplier>TEC001</Supplier>
            <Manufacturer>Seagate</Manufacturer>
            <CustomerReviews>
                <Review>
                    <Reviewer>Hayley Park</Reviewer>
                    <Rating>5</Rating>
                    <Review>I bought this because my boyfriend suggested it. But I am glad I did since it has a good amount of storage. And was quite cheap.</Review>
                </Review>
                <Review>
                    <Reviewer>Bill Gates</Reviewer>
                    <Rating>3</Rating>
                    <Review>Not that big storage wise but can't complain too much about price.</Review>
                </Review>
                <Review>
                    <Reviewer>Jean Pierre Said</Reviewer>
                    <Rating>4</Rating>
                    <Review>So far I've been using this product for a year and have no disregrets since it is much better than the previous hdd which I had which was only 256GB.</Review>
                </Review>
            </CustomerReviews>
        </Item>
        <Item href="" model="ST31000524AS">
            <Name>Seagate Hard disk 1TB ST31000524AS 3.5 inch</Name>
            <Price>55.50</Price>
            <SupplierCode>SCASEA1TB</SupplierCode>
            <Supplier>SCA001</Supplier>
            <Manufacturer>Seagate</Manufacturer>
            <CustomerReviews>
                <Review>
                    <Reviewer>Kyle Werner</Reviewer>
                    <Rating>4</Rating>
                    <Review>Very reliable product and at a great price.</Review>
                </Review>
                <Review>
                    <Reviewer>Scar Russo</Reviewer>
                    <Rating>5</Rating>
                    <Review>My only regret is that I didn't buy this after the price drop. Overall the product is great value for money.</Review>
                </Review>
                <Review>
                    <Reviewer>Stan Lee</Reviewer>
                    <Rating>1</Rating>
                    <Review>I don't know if it's me but this product burned out on me after just 2 weeks.</Review>
                </Review>
            </CustomerReviews>
        </Item>
     </Items>

So the above XML would contain the first element encountered

<Item href="SEA1TBST31000524AS.jpg" model="ST31000524AS">
         <Name>Seagate Hard disk 1TB ST31000524AS 3.5"</Name>
         <Manufacturer>Seagate</Manufacturer>  
</Item>

I would like to know if I could select both prices then select only the best price to display. The other prices could be listed in a tool-tip for example.

and review wise combine them

I know this isn't something simple.

I easily was able to list them with a for each on each item.

But I wanted it too look more refined but the requirement was that no high level language code be used so I ask you guys if this is possible.

Also if possible can items be split into multiple pages you know for example display 5 per page.Although this is not necessary it was just something esthetic which I wondered if it was possible.

Upvotes: 2

Views: 73

Answers (1)

Enzero
Enzero

Reputation: 1141

I did find out how to do what I needed

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="Price">
<xsl:if test="position() = 1">
<li><xsl:value-of select="."/></li>
</xsl:if>
</xsl:template>

<xsl:template match="Search-Request">
<html>
<body>
      <xsl:for-each-group select="Items/Item" group-by="@model">
        <xsl:sort select="@model" data-type="text" order="descending"/>
        <p><xsl:value-of select="@model"/></p>
        <ol>
<xsl:apply-templates select="current-group()/Price">
<xsl:sort select="." data-type="text" order="ascending"/>
</xsl:apply-templates>
        </ol>
      </xsl:for-each-group>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

now I just need to apply the rest of the elements and it will be complete.

Upvotes: 1

Related Questions