This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Grouping (yet again)


At 2002-02-19 16:22 +0100, Steven Noels wrote:
>OK, I give up :-(
>
>Having spent most of the day trying to add some structure to a file, I'm 
>lost on Muenchian stuff :-(

Have you considered instead just using nested loops and variables?  I have 
found this the easiest way to implement nested grouping.

I hope the example below helps.

.......... Ken

t:\ftemp>type noels.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<list>
         <datum day="02" dir="axis" dow="5" group="Downloads" month="11" 
value="74" week="43" year="2001"/>
         <datum day="02" dir="batik" dow="5" group="Downloads" month="11" 
value="87" week="43" year="2001"/>
         <datum day="02" dir="cocoon" dow="5" group="Downloads" month="11" 
value="36" week="43" year="2001"/>
         <datum day="02" dir="cocoon2" dow="5" group="Downloads" month="11" 
value="39" week="43" year="2001"/>
         <datum day="03" dir="crimson" dow="6" group="Downloads" month="11" 
value="29" week="43" year="2001"/>
         <datum day="03" dir="fop" dow="6" group="Downloads" month="11" 
value="72" week="43" year="2001"/>
         <datum day="03" dir="soap" dow="6" group="Downloads" month="11" 
value="115" week="43" year="2001"/>
         <datum day="03" dir="xalan-c" dow="6" group="Downloads" month="11" 
value="3" week="43" year="2001"/>
         <datum day="03" dir="xalan-j" dow="6" group="Downloads" month="11" 
value="38" week="43" year="2001"/>
         <datum day="03" dir="xerces-c" dow="6" group="Downloads" 
month="11" value="81" week="43" year="2001"/>
         <datum day="03" dir="xerces-j" dow="6" group="Downloads" 
month="11" value="350" week="43" year="2001"/>
         <datum day="03" dir="xerces-p" dow="6" group="Downloads" 
month="11" value="8" week="43" year="2001"/>
         <datum day="02" dir="axis" dow="5" group="Uploads" month="11" 
value="74" week="43" year="2001"/>
         <datum day="02" dir="batik" dow="5" group="Uploads" month="11" 
value="87" week="43" year="2001"/>
         <datum day="03" dir="batik" dow="6" group="Uploads" month="11" 
value="4" week="43" year="2001"/>
         <datum day="03" dir="cocoon" dow="6" group="Uploads" month="11" 
value="3" week="43" year="2001"/>
         <datum day="03" dir="cocoon2" dow="6" group="Uploads" month="11" 
value="7" week="43" year="2001"/>
         <datum day="03" dir="crimson" dow="6" group="Uploads" month="11" 
value="29" week="43" year="2001"/>
         <datum day="03" dir="fop" dow="6" group="Uploads" month="11" 
value="72" week="44" year="2001"/>
         <datum day="03" dir="soap" dow="6" group="Uploads" month="11" 
value="115" week="44" year="2001"/>
         <datum day="03" dir="xalan-c" dow="6" group="Uploads" month="11" 
value="3" week="44" year="2001"/>
         <datum day="03" dir="xalan-j" dow="6" group="Uploads" month="11" 
value="38" week="44" year="2001"/>
         <datum day="03" dir="xerces-c" dow="6" group="Uploads" month="11" 
value="81" week="44" year="2001"/>
         <datum day="03" dir="xerces-j" dow="6" group="Uploads" month="11" 
value="350" week="44" year="2001"/>
         <datum day="03" dir="xerces-p" dow="6" group="Uploads" month="11" 
value="8" week="44" year="2001"/>
         <datum day="02" dir="axis" dow="5" group="Downloads" month="11" 
value="74" week="44" year="2001"/>
         <datum day="02" dir="batik" dow="5" group="Downloads" month="11" 
value="87" week="44" year="2001"/>
         <datum day="02" dir="cocoon" dow="5" group="Downloads" month="11" 
value="36" week="44" year="2001"/>
         <datum day="02" dir="cocoon2" dow="5" group="Downloads" month="11" 
value="39" week="44" year="2001"/>
         <datum day="03" dir="cocoon2" dow="6" group="Downloads" month="11" 
value="7" week="44" year="2001"/>
         <datum day="03" dir="crimson" dow="6" group="Downloads" month="11" 
value="29" week="44" year="2001"/>
         <datum day="03" dir="fop" dow="6" group="Downloads" month="11" 
value="72" week="44" year="2001"/>
         <datum day="03" dir="soap" dow="6" group="Downloads" month="11" 
value="115" week="44" year="2001"/>
         <datum day="03" dir="xalan-c" dow="6" group="Downloads" month="11" 
value="3" week="44" year="2001"/>
         <datum day="03" dir="crimson" dow="6" group="Uploads" month="11" 
value="29" week="44" year="2001"/>
         <datum day="03" dir="fop" dow="6" group="Uploads" month="11" 
value="72" week="44" year="2001"/>
         <datum day="03" dir="soap" dow="6" group="Uploads" month="11" 
value="115" week="44" year="2001"/>
         <datum day="03" dir="xalan-c" dow="6" group="Uploads" month="11" 
value="3" week="44" year="2001"/>
         <datum day="03" dir="xalan-j" dow="6" group="Uploads" month="11" 
value="38" week="44" year="2001"/>
         <datum day="03" dir="xerces-c" dow="6" group="Uploads" month="11" 
value="81" week="44" year="2001"/>
         <datum day="03" dir="xerces-j" dow="6" group="Uploads" month="11" 
value="350" week="44" year="2001"/>
         <datum day="03" dir="xerces-p" dow="6" group="Uploads" month="11" 
value="8" week="44" year="2001"/>
       </list>
t:\ftemp>type noels.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 indent="yes"/>

<xsl:template match="/">
   <graph>
     <xsl:variable name="all" select="/list/datum"/>
     <xsl:for-each select="$all">
       <xsl:if test="generate-id(.)=
                     generate-id($all[@group=current()/@group])">
         <data group="{@group}">
           <xsl:variable name="group" select="$all[@group=current()/@group]"/>
           <xsl:for-each select="$group">
             <xsl:if test="generate-id(.)=
                           generate-id($group[concat(@year,@week)=
                                    concat(current()/@year,current()/@week)])">
               <datum week="{@year}{@week}">
                 <xsl:for-each select="$group[concat(@year,@week)=
                                    concat(current()/@year,current()/@week)]">
                   <datum value="{@value}" dir="{@dir}"/>
                 </xsl:for-each>
               </datum>
             </xsl:if>
           </xsl:for-each>
         </data>
       </xsl:if>
     </xsl:for-each>
   </graph>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>xt noels.xml noels.xsl
<?xml version="1.0" encoding="utf-8"?>
<graph>
<data group="Downloads">
<datum week="200143">
<datum value="74" dir="axis"/>
<datum value="87" dir="batik"/>
<datum value="36" dir="cocoon"/>
<datum value="39" dir="cocoon2"/>
<datum value="29" dir="crimson"/>
<datum value="72" dir="fop"/>
<datum value="115" dir="soap"/>
<datum value="3" dir="xalan-c"/>
<datum value="38" dir="xalan-j"/>
<datum value="81" dir="xerces-c"/>
<datum value="350" dir="xerces-j"/>
<datum value="8" dir="xerces-p"/>
</datum>
<datum week="200144">
<datum value="74" dir="axis"/>
<datum value="87" dir="batik"/>
<datum value="36" dir="cocoon"/>
<datum value="39" dir="cocoon2"/>
<datum value="7" dir="cocoon2"/>
<datum value="29" dir="crimson"/>
<datum value="72" dir="fop"/>
<datum value="115" dir="soap"/>
<datum value="3" dir="xalan-c"/>
</datum>
</data>
<data group="Uploads">
<datum week="200143">
<datum value="74" dir="axis"/>
<datum value="87" dir="batik"/>
<datum value="4" dir="batik"/>
<datum value="3" dir="cocoon"/>
<datum value="7" dir="cocoon2"/>
<datum value="29" dir="crimson"/>
</datum>
<datum week="200144">
<datum value="72" dir="fop"/>
<datum value="115" dir="soap"/>
<datum value="3" dir="xalan-c"/>
<datum value="38" dir="xalan-j"/>
<datum value="81" dir="xerces-c"/>
<datum value="350" dir="xerces-j"/>
<datum value="8" dir="xerces-p"/>
<datum value="29" dir="crimson"/>
<datum value="72" dir="fop"/>
<datum value="115" dir="soap"/>
<datum value="3" dir="xalan-c"/>
<datum value="38" dir="xalan-j"/>
<datum value="81" dir="xerces-c"/>
<datum value="350" dir="xerces-j"/>
<datum value="8" dir="xerces-p"/>
</datum>
</data>
</graph>

t:\ftemp>


--
Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO - Feb 18-22, 2002

G. Ken Holman                mailto:gkholman@CraneSoftwrights.com
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 & 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-02-18,21,27,03-04,05,06,11,15,
-           04-08,09,10,11,05-06,07,09,10,20,06-04,07,10,11,13,14


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]