|
next
|
Subject: XSLT group and sort whith generate-id and key Author: anabou moloud Date: 17 Jun 2009 12:20 PM
|
With file xml below,i look for :
all items ( productid) not = "1" in all orders (orderid) wich contains productid=1 (following-sibling) ,regrouped and sorted by sum of quantity for product in all the file (customer who bought item 1 also bought items ...),
i try the rules xslt below,but i get the products,if they are n't missed, regrouped and sorted in each orderid and not one time for all file.
have you an idea please (excuse my english...)
++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="utf-8" ?>
<orders>
<order>
<orderid>1</orderid>
<productid>1</productid>
<quantity>10</quantity>
<unitcost>12,13</unitcost>
</order>
<order>
<orderid>1</orderid>
<productid>4</productid>
<quantity>11</quantity>
<unitcost>80</unitcost>
</order>
<order>
<orderid>2</orderid>
<productid>2</productid>
<quantity>3</quantity>
<unitcost>100</unitcost>
</order>
<order>
<orderid>2</orderid>
<productid>2</productid>
<quantity>4</quantity>
<unitcost>60</unitcost>
</order>
<order>
<orderid>3</orderid>
<productid>2</productid>
<quantity>5</quantity>
<unitcost>100</unitcost>
</order>
<order>
<orderid>3</orderid>
<productid>1</productid>
<quantity>8</quantity>
<unitcost>12,13</unitcost>
</order>
<order>
<orderid>3</orderid>
<productid>9</productid>
<quantity>1</quantity>
<unitcost>100</unitcost>
</order>
<order>
<orderid>4</orderid>
<productid>1</productid>
<quantity>1</quantity>
<unitcost>12,13</unitcost>
</order>
<order>
<orderid>4</orderid>
<productid>3</productid>
<quantity>2</quantity>
<unitcost>6,28</unitcost>
</order>
<order>
<orderid>5</orderid>
<productid>3</productid>
<quantity>2</quantity>
<unitcost>6,28</unitcost>
</order>
<order>
</orders>
+++++++++++XSLT++++++++++++++++++++++++++++++++++++++
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:param name="parmt" select="1"></xsl:param>
<xsl:variable name="vart" select="//orderid[../productid=$parmt]"></xsl:variable>
<!--<xsl:key name="keyregrp" match="productid" use="substring-before(concat(normalize-space(.),'|',preceding-sibling::orderid),'|')"/>-->
<xsl:key name="keyregrp" match="productid" use="."/>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<xsl:template match="/">
<Newdataset>
<xsl:apply-templates select="//orderid[../productid=$parmt]">
</xsl:apply-templates>
</Newdataset>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<xsl:template match="orderid">
<xsl:text>
</xsl:text>
<xsl:variable name="ord" select="."/>
<!--orderid <xsl:value-of select="."/> key3+
<xsl:apply-templates select="."/>
key <xsl:value-of select="key('keyregrp',concat(.,current()))"/>++-->
<xsl:apply-templates select="//productid[../orderid=current() and .!=$parmt and generate-id()=generate-id(key('keyregrp',.)[1])]" >
<xsl:sort select="." data-type = "number" order="descending"></xsl:sort>
</xsl:apply-templates>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<xsl:template match="productid">
<Tableg>
<productid>
<xsl:value-of select="."/>
</productid>
Q <quantity>
<xsl:value-of select="sum(//quantity[normalize-space(../productid)=normalize-space(current())])"/>
</quantity>;
</Tableg>
</xsl:template>
</xsl:stylesheet>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|