[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: looping within a key's nodeset

Subject: Re: looping within a key's nodeset
From: Markus Abt <abt@xxxxxxxx>
Date: Fri, 25 Feb 2005 17:08:13 +0100
xsl key muenchen
Hi Matt,

to use multiple grouping values with Munchnian grouping, combine
the grouping values using concat(), and use this combined value in
the key:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:key name="ETL_2_groups" match="ETL_2" use="concat (@SLOT_ACCT_NM, ' ',
@SLOT_NM, ' ', @POT_ACCT_NM)"/>
<xsl:template match="doc">
  <doc>
    <xsl:for-each select="ETL_2[generate-id()=generate-id(key('ETL_2_groups',
concat (@SLOT_ACCT_NM, ' ', @SLOT_NM, ' ', @POT_ACCT_NM)))]">
      <gr>Group: <xsl:value-of select="concat (@SLOT_ACCT_NM, ' ', @SLOT_NM, '
', @POT_ACCT_NM)"/></gr>
      <xsl:apply-templates select="key('ETL_2_groups', concat (@SLOT_ACCT_NM,
' ', @SLOT_NM, ' ', @POT_ACCT_NM))"/>
    </xsl:for-each>
  </doc>
</xsl:template>
<xsl:template match="ETL_2">
  <etl2>
    <xsl:value-of select="@SLOT_ACCT_NM"/>,
    <xsl:value-of select="@SLOT_NM"/>,
    <xsl:value-of select="@POT_ACCT_NM"/>,
    <xsl:value-of select="@POT_NM"/>
  </etl2>
</xsl:template>
</xsl:stylesheet>

Regards,
Markus

__________________________
Markus Abt
Comet Computer GmbH
Rueckertstrasse 5
80336 Muenchen
GERMANY
Phone +49 89 5445 6045
Fax +49 89 5445 6046
http://www.comet.de
mailto:abt@xxxxxxxx


----------
Von: 	Heckel, Matt , Ctr, OSD-PA&E
Gesendet: 	Freitag, 25. Februar 2005 13:59
An: 	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Betreff: 	 looping within a key's nodeset

Classification: UNCLASSIFIED

First of all.. Let me start by saying I'm not using XSL for a classic
enterprise type application.
So what I'm asking, is a little beyond the typical questions asked on this
board.  It's not that its hard.. its just that most people probably don't
run into this situation and so finding help or examples has been difficult.
Much appreciation for those who respond.

I'm pulling data from a database.  The table in the db has multiple
rows(elements) for one of the elements' attributes.  As in.. ther is a one
to many relationship between a particular attribute within an element and
other attributes within other elements.  There are then 1 to many other
attributes for each of the attributes previously described. For example:

<doc>
<ETL_2 SLOT_ACCT_NM="MH1553" SLOT_NM="MH1550" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-0" POT_NM="ally"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1553" SLOT_NM="MH1550" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-1" POT_NM="ally-1"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1553" SLOT_NM="MH1551" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-4" POT_NM="ally-4"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1553" SLOT_NM="MH1551" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-5" POT_NM="ally-5"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1554" SLOT_NM="MH1553" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-0" POT_NM="ally"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1554" SLOT_NM="MH1553" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-1" POT_NM="ally-1"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1554" SLOT_NM="MH1554" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-0" POT_NM="ally"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>

<ETL_2 SLOT_ACCT_NM="MH1554" SLOT_NM="MH1554" ALTRN_SLOT_NM="null"
	POT_ACCT_NM="MH1553-1" POT_NM="ally-1"
        ALTRN_SLOT_1_NM="null"  ALTRN_SLOT_2_NM="null"/>
</doc>

I need to group the data on the SLOT_ACCT_NM attribute to create a nodesets
with elements having the same SLOT_ACCT_NMs.  Then for each nodeset, I need
to iterate through using UNIQUE SLOT_NM attributes as the index for the
loop.  Inside of that loop iteration, I then need to be able to iterate
through the nodeset using UNIQUE only POT_ACCT_NM attributes to get all the
POT_NMs associated
with each unique POT_ACCT_NM.  Essentially, I'm recombining data that has
been normalized for a db and I need to be able to loop inside of loops all
the while having access to all the elements in the nodeset.  I've been using
the Muenchian technique for my initial grouping but am lost after passing
the nodeset for each group through an xsl:apply-templates call.

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:key name="ETL_2_groups" match="ETL_2" use="@SLOT_ACCT_NM"/>

           <xsl:for-each
="ETL_2[generate-id()=generate-id(key('ETL_2_groups', @SLOT_ACCT_NM))]">

                   <xsl:apply-templates select="key('ETL_2_groups',
@SLOT_ACCT_NM)"/>

           </xsl:for-each>
       </doc>
   </xsl:template>
   <xsl:template match="ETL_2">
      How do I loop through the nodeset thats been passed?  THANK YOU~
   </xsl:template>
</xsl:stylesheet>


If I haven't explained my situation clearly enough I'd be happy to try
again..

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.