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 December 14th, 2005, 10:28 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Grouping Help

Hi,

I am trying to group a collection of nodes using XSLT 1.0. I almost have the solution, but I get a duplicate of the SERVICE_INSTANCE_DESC in the output. I am trying to group on the SERVICE_INSTANCE_DESC node. I also need to filter on the SERVICE_LOCATION_ID, as the ACCOUNT_ID can have multiple SERVICE_LOCATION_ID's and the output is displayed based on a href passing the SERVICE_LOCATION_ID into the street_name parameter.

XSLT:-
<xsl:key name="account" match="row" use="SERVICE_INSTANCE_DESC"/>

<xsl:template match="data_results">
    <xsl:for-each select="row[count(. | key('account', SERVICE_INSTANCE_DESC)[1]) = 1]">
        <xsl:sort select="SERVICE_INSTANCE_DESC" />
            <xsl:for-each select="key('account',SERVICE_INSTANCE_DESC)">
                <xsl:if test ="SERVICE_LOCATION_ID = $street_name">
                    <xsl:variable name="first_instance" select="SERVICE_INSTANCE_DESC[1]" />
                    <b><xsl:value-of select="$first_instance" /></b><br />
                </xsl:if>
            </xsl:for-each>

            <xsl:for-each select="key('account', SERVICE_INSTANCE_DESC)">
                <xsl:sort select="MODEL_NAME" />
                <xsl:if test ="SERVICE_LOCATION_ID = $street_name">
                       <xsl:value-of select="SERVICE_LOCATION_ID" /><br />
                    <xsl:value-of select="MODEL_NAME" /><br /><br />
                </xsl:if>
              </xsl:for-each>
      </xsl:for-each>


XML:-
<data_results>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>OUTLET</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Atlas Satellite Set Top</MODEL_NAME>
</row>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>OUTLET</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>Family Room</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Titan Set Top</MODEL_NAME>
</row>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>Family Room</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>Bedroom</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Titan Set Top</MODEL_NAME>
</row>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>Bedroom</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
<row>
  <ACCOUNT_ID>9999999</ACCOUNT_ID>
  <SERVICE_LOCATION_ID>222222</SERVICE_LOCATION_ID>
  <SERVICE_INSTANCE_DESC>Family Room</SERVICE_INSTANCE_DESC>
  <MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
</data_results>

Output:-
Bedroom
Bedroom
111111
Irdeto Delta V4

111111
Titan Set Top

Family Room
Family Room
111111
Irdeto Delta V4

111111
Titan Set Top

OUTLET
OUTLET
111111
Atlas Satellite Set Top

111111
Irdeto Delta V4

Desired Output:-
Bedroom
111111
Irdeto Delta V4

111111
Titan Set Top

Family Room
111111
Irdeto Delta V4

111111
Titan Set Top

OUTLET
111111
Atlas Satellite Set Top

111111
Irdeto Delta V4

I tried using
<xsl:template match = "/data_results" >
    <xsl:apply-templates select ="row[(SERVICE_LOCATION_ID = $street_name)]" />
</xsl:template>
but had problems with the count in the <xsl:for-each select="row[count(. | key('account', SERVICE_INSTANCE_DESC)[1]) = 1]">

I am new to keys and grouping, so any help is appreciated.
Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem of grouping in XSLT LeoMathew XSLT 2 September 11th, 2008 09:38 AM
Grouping with XSLT 1.0 rodmcleay XSLT 1 January 14th, 2008 11:42 PM
XSLT Grouping vernc XSLT 2 October 2nd, 2007 03:59 AM
XSLT 1.0 Grouping kwilliams XSLT 0 January 11th, 2006 06:30 PM
Grouping Elements using XSLT mathuranuj XSLT 2 June 21st, 2005 02:56 AM





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