Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2008, 09:16 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Have you tried the code? For your input sample it gives you two group elements, one with two elements, the second with one element. If you want to process distinct elements you would only process the first element in each group.
You have already been pointed to http://www.jenitennison.com/xslt/grouping, it explains how Muenchian grouping works.

 
Old March 18th, 2008, 05:00 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have created a key


<xsl:key name="prepackIndicatorUpcCodeKey" match="LineItem"
use="concat(VariableDataSet/VariableDataElement[@Code = '750']/@Value, '-', VariableDataSet/VariableDataElement[@Code = '790']/@Value)" />

and assigned it to a variable
<xsl:variable name="distinctPrepackIndicatorUpcCode"
    select="$activeLineItems[generate-id(.) = generate-id(key('prepackIndicatorUpcCodeKey', concat(VariableDataSet/VariableDataElement[@Code = '750']/@Value, '-',
VariableDataSet/VariableDataElement[@Code = '790']/@Value))[1])]" />


After this i am looping through the above records returned from $distinctPrepackIndicatorUpcCode.

<table>
<xsl:for-each select="$distinctPrepackIndicatorUpcCode">
<tr>
<td>Prepack Item:</td>
<td><xsl:value-of select="./VariableDataElement[@Code='750']"/></td>
<td>Prepack UPC:</td>
<td><xsl:value-of select="1"/></td>
</tr>
</table>

Here i want to retrieve the VariableDataSet/VariableDataElement[@Code = '750']/@Value and VariableDataSet/VariableDataElement[@Code = '790']/@Value seperately and display above for Prepack Item and Prepack UPC.

I tried giving VariableDataSet/VariableDataElement[@Code = '750']/@Value but it does not get me the value.

 
Old March 18th, 2008, 07:17 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Your variable is a node-set of 'LineItem' elements. The 'VariableDataElement' elements are not children of 'LineItem' elements, rather they are grandchildren contained in a 'VariableDataSet' element. Furthermore the 'VariableDataElement' elements are empty and don't have any contents so I don't understand why you use <xsl:value-of select="./VariableDataElement[@Code='750']"/>.



 
Old March 18th, 2008, 07:31 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was able to retrive the data.Thanks

 
Old March 19th, 2008, 06:29 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Based on the key i was able to get the distinct set of values.But these values can have multiple records(like multiple LineItems havign the same values).

I am able to loop through the distinct values returned by the key(concat(VariableDataSet/VariableDataElement[@Code = '750']/@Value, '-',
VariableDataSet/VariableDataElement[@Code = '790']/@Value)).

But i dont know how can i loop through the LineItems for each distinct value.



 
Old March 19th, 2008, 06:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I had already posted an example that processes the first LineItem element with a distinct key value:
Code:
     <xsl:apply-templates
        select="LineItem[generate-id() = generate-id(key('group', concat(VariableDataSet/VariableDataElement[@Name = 'Prepack Indicator']/@Value,
                       '_',
                       VariableDataSet/VariableDataElement[@Name = 'UPC Code']/@Value))[1])]"/>
You have choosen a slightly different key but otherwise you can use the same approach.

 
Old March 19th, 2008, 07:08 AM
Authorized User
 
Join Date: Feb 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So in this case should i need to use the for-each loop to loop through the LineItems.Should i be using the key value.

<xsl:template match="LineItem">
    <group key="{concat(VariableDataSet/VariableDataElement[@Name = 'Prepack Indicator']/@Value,'_', VariableDataSet/VariableDataElement[@Name = 'UPC Code']/@Value)}"

           item-count="{count(key('group', concat(VariableDataSet/VariableDataElement[@Name = 'Prepack Indicator']/@Value,
                       '_',
                       VariableDataSet/VariableDataElement[@Name = 'UPC Code']/@Value)))}"/>
  </xsl:template>

 
Old March 19th, 2008, 07:45 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You can use either xsl:for-each or xsl:apply-templates but if you use xsl:apply-templates as in my example then the predicate
Code:
LineItem[generate-id() = generate-id(key('key-name', keyvalue)[1])]
already makes sure that only the LineItem elements with a distinct key are processed.







Similar Threads
Thread Thread Starter Forum Replies Last Post
getting distinct values from attribute markus2000 XSLT 1 June 13th, 2006 03:06 AM
Unable to fetch textbox values triveni_sh BOOK: Professional Crystal Reports for VS.NET 0 January 5th, 2006 01:28 AM
how to fetch records from website avats ADO.NET 0 November 3rd, 2005 03:45 PM
Distinct values of data arnabghosh Access 18 September 13th, 2005 05:41 PM
Field Specific DISTINCT Statement tdaustin Classic ASP Basics 1 March 30th, 2004 12:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.