Re: [xsl] Acheiving ..2nd level grouping but with differentnode structure ..

Subject: Re: [xsl] Acheiving ..2nd level grouping but with differentnode structure ..
From: "KUMAR NINGASHETTY" <kningashetty@xxxxxxxxxxxxxxxx>
Date: Wed, 24 Jul 2002 13:42:09 -0400
Hi ken
    Thanks for your time and solution .. It works great .. The reason i was trying to use KEYS was i will be later summing  and doing an
    average across rows  (not horizontally, but vertically) and i should be able to sort...
    For that reason i thought key may be convenient .. I am not sure about the PERFORMANCE though ...

thanks again for your inputs ..
 -kumar



>>> gkholman@xxxxxxxxxxxxxxxxxxxx 07/24/02 10:17AM >>>
At 2002-07-24 10:02 -0400, I wrote:
>At 2002-07-24 08:59 -0400, KUMAR NINGASHETTY wrote:
>>    This seemed little different having different parent nodes for 2nd 
>> level grouping using keys ..
>
>Sometimes using keys isn't always the easiest for multiple-level grouping.
>
>Consider the solution below that doesn't use keys at all, but uses 
>variables instead.

I thought of a faster version that reuses a variable and doesn't revisit 
the source node tree for the table cells, and copied it below.  The lines 
are supposed to wrap after column 79

I hope this helps.

.................. Ken

T:\ftemp>type kumar.xml
<rep>
   <uwr>
         <los userid="1014" reg="Region 4">
                 <review type="N"><![CDATA[11]]></review>
                 <review type="Y"><![CDATA[16]]></review>
         </los>
         <los userid="1017" reg="Region 4">
                 <review type="N"><![CDATA[7]]></review>
                 <review type="Y"><![CDATA[17]]></review>
         </los>
         <los userid="1025" reg="Region 2">
                 <review type="N"><![CDATA[13]]></review>
                 <review type="Y"><![CDATA[12]]></review>
         </los>
   </uwr>
   <arr>
         <los userid="1014" reg="Region 4">
                 <review type="N"><![CDATA[15]]></review>
                 <review type="Y"><![CDATA[19]]></review>
         </los>
         <los userid="1017" reg="Region 4">
                 <review type="N"><![CDATA[20]]></review>
                 <review type="Y"><![CDATA[22]]></review>
         </los>
         <los userid="1025" reg="Region 2">
                 <review type="N"><![CDATA[23]]></review>
                 <review type="Y"><![CDATA[25]]></review>
         </los>
   </arr>
</rep>

T:\ftemp>type kumar.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
   <xsl:variable name="los" select="/*/*/los"/>
   <xsl:for-each select="$los">
     <xsl:if test="generate-id(.)=
                   generate-id($los[@reg=current()/@reg])">
       <xsl:text>
</xsl:text>
<xsl:value-of select="@reg"/>
   Userid  UWR(n)  UWR(Y)  ARR(N)  ARR(Y)
<xsl:variable name="regs" select="$los[@reg=current()/@reg]"/>
       <xsl:for-each select="$regs">
         <xsl:if test="generate-id(.)=
                       generate-id($regs[@userid=current()/@userid])">
           <xsl:text>   </xsl:text>
           <xsl:value-of select="@userid"/>
           <xsl:text>     </xsl:text>
           <xsl:value-of
       select="$los[parent::uwr][@userid=current()/@userid]/review[@type='N']"/>
           <xsl:text>      </xsl:text>
           <xsl:value-of
       select="$los[parent::uwr][@userid=current()/@userid]/review[@type='Y']"/>
           <xsl:text>      </xsl:text>
           <xsl:value-of
       select="$los[parent::arr][@userid=current()/@userid]/review[@type='N']"/>
           <xsl:text>      </xsl:text>
           <xsl:value-of
       select="$los[parent::arr][@userid=current()/@userid]/review[@type='Y']"/>
           <xsl:text>
</xsl:text>
         </xsl:if>
       </xsl:for-each>
     </xsl:if>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt kumar.xml kumar.xsl

Region 4
   Userid  UWR(n)  UWR(Y)  ARR(N)  ARR(Y)
    1014     11      16      15      19
    1017     7      17      20      22

Region 2
   Userid  UWR(n)  UWR(Y)  ARR(N)  ARR(Y)
    1025     13      12      23      25

T:\ftemp>rem Done!



--
Upcoming hands-on in-depth 3-days XSLT/XPath and/or 2-days XSL-FO:
                                 North America:  Sep 30-Oct  4,2002
                                 Japan:          Oct  7-Oct 11,2002

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx 
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/ 
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1                Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed),
articles, training (instructor-live,Internet-live,web/CD,licensed)
Next public training:           2002-08-05,26,27,09-30,10-03,07,10


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread