xsl-list
[Top] [All Lists]

Re: looping within a key's nodeset

2005-02-25 09:08:13
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(_at_)comet(_dot_)de


----------
Von:    Heckel, Matt , Ctr, OSD-PA&E
Gesendet:       Freitag, 25. Februar 2005 13:59
An:     xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff:        [xsl] 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..

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>