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  
Posttop
CCP UserSubject: XSL to select the group of rows based on the three XML fields and with these conditions.
Author: CCP User
Date: 21 Oct 2010 06:06 PM
I would like to group based on fields of row element (combination of
StackNumber,BlockNumber and LocationCode) and select only higher
BookVersion (BookVersion) based rows in particular group(combination
of StackNumber,BlockNumber and LocationCode) and also to select the
rows of DeliveryMode with the value as TRANSIT.

Here is the input document

<?xml version="1.0"?>
<Output>
<row>
<StackNumber>19</StackNumber>
<BlockNumber>61001</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>03</BookVersion>
<StoreNumber>1010</StoreNumber>

</row>
<row>
<StackNumber>20</StackNumber>
<BlockNumber>61001</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>01</BookVersion>
<StoreNumber>1011</StoreNumber>
</row>
<row>
<StackNumber>20</StackNumber>
<BlockNumber>61001</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>02</BookVersion>
<StoreNumber>1013</StoreNumber>
</row>
<row>
<StackNumber>21</StackNumber>
<BlockNumber>61001</BlockNumber>
<DeliveryMode>RECVD</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>03</BookVersion>
<StoreNumber>1022</StoreNumber>
</row>
<row>
<StackNumber>21</StackNumber>
<BlockNumber>61001</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>03</BookVersion>
<StoreNumber>1022</StoreNumber>
</row>
<row>
<StackNumber>22</StackNumber>
<BlockNumber>15098</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>01</BookVersion>
<StoreNumber>1010</StoreNumber>
</row>
<row>
<StackNumber>22</StackNumber>
<BlockNumber>22456</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>02</BookVersion>
<StoreNumber>1011</StoreNumber>
</row>
<row>
<StackNumber>22</StackNumber>
<BlockNumber>22456</BlockNumber>
<DeliveryMode>TRANSIT</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>03</BookVersion>
<StoreNumber>1012</StoreNumber>
</row>
<row>
<StackNumber>22</StackNumber>
<BlockNumber>22456</BlockNumber>
<DeliveryMode>RECVD</DeliveryMode>
<LocationCode>MON</LocationCode>
<BookVersion>02</BookVersion>
<StoreNumber>1021</StoreNumber>
</row>
</Output>
XSL (using saxon 9 parser) that I wrote:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:key name="transitGroup" match="row"
use="concat(StackNumber,BlockNumber,LocationCode)"/>

<xsl:template match="/">
<Output>
<xsl:for-each select="//row[generate-id(.) =
generate-id(key('transitGroup',concat(StackNumber,BlockNumber,LocationCode))[1])]">
<xsl:variable name="BookVersion"
select="key('transitGroup',concat(StackNumber,BlockNumber,LocationCode))/BookVersion"/>
<xsl:if test="DeliveryMode = 'TRANSIT'">
<row>
<StackNumber>
<xsl:value-of select="StackNumber"/>
</StackNumber>
<BlockNumber>
<xsl:value-of select="BlockNumber"/>
</BlockNumber>
<LocationCode>
<xsl:value-of select="LocationCode"/>
</LocationCode>
<StoreNumber>
<xsl:value-of select="StoreNumber"/>
</StoreNumber>

<xsl:for-each select="$BookVersion">

<xsl:sort select="." data-type="number"
order="descending"/>

<xsl:if test="position()=1">

<BookVersion>
<xsl:value-of select="."/>
</BookVersion>
</xsl:if>
</xsl:for-each>
</row>
</xsl:if>
</xsl:for-each>
</Output>
</xsl:template>
</xsl:stylesheet>


I wrote this above one but can't figure out to select correct store
number based on greater value based element 'BookVersion' in each
group.

example group must be printed like this .

<row>
<StackNumber>20</StackNumber>
<BlockNumber>61001</BlockNumber>
<LocationCode>MON</LocationCode>
<StoreNumber>1013</StoreNumber>
<BookVersion>02</BookVersion>
</row>

I'm getting wrong store number here for a particular selected group.
I'm struck to proceed further here, I will appreciate if some body can
lead me the way to write correct it in this XSL.

   
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.