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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.