xsl-list
[Top] [All Lists]

Re: grouping node-sets in an external document

2003-01-10 15:35:14
Folks,

I have to apologize.  I'm an idiot.  So much for TGIF drink specials...  Of 
course the right way to do this is not to use group at all for the external 
document.  There's no reason to use the muenchian method twice.

However, this leads to another problem.  In this example, I'd really like to 
sum 
up all the students for all the class types.  What if the original 
'firstGraders.xml' document did not contain a class type of 'reading', but the 
'newFirstGraders.xml' document does.  I sure would like a way to get all the 
unique groups between two files.  That is..

file1.xml
<class type="math"/>
   <data .../>
<class type="science"/>
   <data .../>   
<class type="math"/>
   <data .../>
<class type="math"/>
   <data .../>

file2.xml
<class type="science"/>
   <data .../>
<class type="math"/>
   <data .../>

how could I group up data for all three groups without knowing how many groups 
I 
have before hand?

Carl

Date: Fri, 10 Jan 2003 14:01:26 -0800 (PST)
From: Carl Yu <yuc>
Subject: Re: grouping node-sets in an external document (revised)
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Mime-Version: 1.0
Content-MD5: WpEqku4z4vldlvjf2V/A5g==

Oops made a typo, please see the following..

Date: Fri, 10 Jan 2003 13:57:34 -0800 (PST)
From: Carl Yu <yuc>
Subject: grouping node-sets in an external document
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Mime-Version: 1.0
Content-MD5: ZGylNKg54SnZJjY2KRj61Q==

I'm trying to apply the Muenchian grouping method to an external document.  
Of 
course, this doesn't work because the document function doesn't work within 
match statements.  Am I going around this the wrong way?

newFirstGraders.xml
<class name="101" type="math">
  <student>Bob</student>
  <student>Joe</student>
  <student>Mary</student>
</class>
<class name="201" type="science">
  <student>Bob</student>
  <student>Joe</student>
  <student>Mary</student>
</class>
<class name="301" type="math">
  <student>John</student>
  <student>Peter</student>
</class>

firstGraders.xml
<class name="101" type="math">
  <student>Fred</student>
  <student>Mark</student>
</class>
<class name="201" type="science">
  <student>Paul</student>
</class>
<class name="301" type="math">
  <student>Wendy</student>
</class>

generateSchoolReport.xsl
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="xml" indent="yes" />

<xsl:key name="newstudents" match="document('class101.xml')/class/student" 
use="../@type" />
<xsl:key name="students" match="/class/student" use="../@type" />

<xsl:template match="/class/student">
  <xsl:apply-templates 
select="/class/student[generate-id(.)=generate-id(key('students', 
../@type))]" 
/> mode="uniqueType" />
</xsl:template>

<xsl:template match="/class/student" mode="uniqueType">
Number of Math Students: <xsl:value-of select="count(key('students','math')) 
+ 
count(key('newstudents', ../@type))" /></xsl:attribute>

This should be :

Number of <xsl:value-of select="../@type" /> students: <xsl:value-of 
select="count(key('students', ../@type)) + count(key('newstudents', 
../@type))" 
/>

instead.

</xsl:template>

</xsl:transform>

Is there a way to do this (while still grouping unique groups across 
documents)? 
Has this already been covered.  It feels familiar, but I couldn't find a 
relevant solution through searching.  I know this XSL looks bad -- I'm new... 
and this XSL was extracted from a far more complex XSL algorithm.  Given this 
example, I'm sure you can write a better template match that does not require 
the 'function' call trick of using a mode='uniqueType'.  I'm just too lazy to 
make a better example, sorry.

Carl

Carl


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



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