XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
anabou moloudSubject: 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>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Postnext
(Deleted User) Subject: XSLT group and sort whith generate-id and key
Author: (Deleted User)
Date: 19 Jun 2009 10:33 AM
I would something like this:

<xsl:template match="/">
<Newdataset>
<xsl:for-each select="//productid[.!=$parmt and ../orderid = //order[productid=$parmt]/orderid]">
<xsl:sort select="sum(//quantity[normalize-space(../productid)=normalize-space(current())])" data-type = "number" order="descending"/>
<Tableg>
<productid><xsl:value-of select="."/></productid>
<quantity><xsl:value-of select="sum(//quantity[normalize-space(../productid)=normalize-space(current())])"/></quantity>
</Tableg>
</xsl:for-each>
</Newdataset>
</xsl:template>

Alberto

Postnext
anabou moloudSubject: XSLT group and sort whith generate-id and key
Author: anabou moloud
Date: 20 Jun 2009 08:37 AM
OK ,but i still have problem with group nodes productid when using $parmt ,system send error ,"something like this :reference

in key not accepted",thanks for help:
code seems now like this:

<xsl:param name="parmt" select="1"></xsl:param>
<xsl:key name="keyregrp" match="productid[../orderid = //order[productid=$parmt]/orderid]" use="."/>
<xsl:template match="/">
<Newdataset>
<xsl:for-each select="//productid[.!=$parmt and ../orderid = //order[productid=$parmt]/orderid and

generate-id()=generate-id(key('keyregrp',.)[1])]">


Posttop
(Deleted User) Subject: XSLT group and sort whith generate-id and key
Author: (Deleted User)
Date: 23 Jun 2009 04:21 AM
Hi,
in XSLT the xsl:key instruction cannot reference variables; its job is to index data, not to filter it.

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.