Xml XSL按项分组模型

Xml XSL按项分组模型,xml,xslt,Xml,Xslt,我的问题是,我想为每个项目按模型分组,但我只想加载单个实体的详细信息 <Search-Request search-term="1 tb"> <Items> <Item href="SEA1TBST31000524AS.jpg" model="ST31000524AS"> <Name>Seagate Hard disk 1TB ST31000524AS 3.5"</Name>

我的问题是,我想为每个项目按模型分组,但我只想加载单个实体的详细信息

<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>

希捷硬盘1TB ST31000524AS 3.5“
60.50
TECSEA1TB
TEC001
希捷
海利公园
5.
我买这个是因为我男朋友建议的。但我很高兴我买了,因为它有很好的存储空间。而且很便宜。
比尔盖茨
3.
存储空间不是很大,但也不能对价格抱怨太多。
让·皮埃尔说
4.
到目前为止,我已经使用这个产品一年了,而且没有出现任何问题,因为它比我以前的硬盘要好得多,我以前的硬盘只有256GB。
希捷硬盘1TB ST31000524AS 3.5英寸
55.50
SCASEA1TB
SCA001
希捷
凯尔·沃纳
4.
非常可靠的产品和一个伟大的价格。
斯卡·鲁索
5.
我唯一的遗憾是,在价格下跌后我没有买这个。总的来说,这个产品物有所值。
斯坦·李
1.
我不知道是不是我的问题,但仅仅两周后,这个产品就让我筋疲力尽了。

因此,上面的XML将包含遇到的第一个元素

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

希捷硬盘1TB ST31000524AS 3.5“
希捷
我想知道我是否可以选择两个价格,然后只选择最好的价格显示。例如,其他价格可以在工具提示中列出

并将它们结合起来

我知道这不是件简单的事

我很容易就能在每一个项目上列出它们,每个项目都有一个

但我也希望它看起来更精致,但要求是不使用高级语言代码,所以我问你们这是否可行


此外,如果可能的话,可以将项目拆分为多个页面,例如,您知道的每页显示5个。虽然这不是必需的,但我想知道这是否可能。我确实找到了如何做我需要的事情

<?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>


  • 现在我只需要应用其余的元素,就可以完成了。

    这是一项非常简单的任务。您要查找的关键字是“慕尼黑分组”和“
    ”。光是StackOverflow就有成百上千的例子。您需要指定输出HTML的确切外观(我认为到目前为止您还没有这样做)。然后,请尝试自己解决它,并张贴一个代码样本时,你被卡住了。对于下一个XSLT问题,不要忘了提到您使用的是XSLT 2.0。@Tomalak我不是针对XSLT 2的,但我发现解决方案似乎更简单。它是。无论如何,比XSLT1.0要简单。这正是解决这个问题的正确方法。