xsl-list
[Top] [All Lists]

RE: A more complicated Muenchian Method exercise

2003-07-21 09:05:15
Américo Albuquerque,
Thank you for the effort, but I don't think you captured what I was trying
to accomplish.

The key:
<xsl:key match="header" name="key2_name"
use="concat(date,':',sender/sen_id,':',sender/recipient/rec_id)"/>

seems to be a cartesion product, instead of a union.  Unless I am incorrect?
and the TRADING PARTNER is the union of sender/sen_id and
sender/recipient/rec_id, not just made of senders.
<xsl:template match="header" mode="level2">
   <xsl:text>&#160;&#160;&#160;&#160;TRADING PARTNER: &quot;</xsl:text>
   <xsl:value-of select="sender/sen_id"/>

The XML Structure is from MS SQL, and so the nesting structure does not
follow the actual logical grouping of the data.
Senders and Recipients should be at the same (header) level, instead of
nested, but I'm stuck with what MSSQL gives me.  I want to group the
document ids on (Senders AND Recipients).  Each document ID appears twice in
the report: once under the sender, and once under the recipient, for that
date.


-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Américo
Albuquerque
Sent: Monday, July 21, 2003 11:29 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] A more complicated Muenchian Method exercise


Hi

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Greg Johnson
Sent: Monday, July 21, 2003 2:30 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] A more complicated Muenchian Method exercise


In this last week and a half, I have been on a serious
learning curve, and this list has helped me a lot.  Thanks.
Now I need some more.  :)

I have the following (abbreviated) XML Structure

<report>

<header>
<date></date>
<sender>
<sen_id></sen_id>
<recipient>
  <rec_id></rec_id>
  <detail></detail>
  <detail></detail>
</recipient>
</sender>
</header>

<header>
<date></date>
<sender>
<sen_id></sen_id>
<recipient>
  <rec_id></rec_id>
  <detail></detail>
  <detail></detail>
  <detail></detail>
</recipient>
</sender>
</header>

...

</report>


I would like to make a report based on the above XML that has
a primary grouping by "date", which is no problem. What I'm
not sure about is how to do a second grouping on the UNIONED
SET of senders and recipients.  That is, I have a set called
"Trading Partner", of which "sender" and "recipients" are
members.  That way I can then produce an output that groups
on TP's, and then I could output the documents that were
received, and then sent for a particular "Trading Partner".  Like the
following:

REPORT
  DATE1
    TRADING PARTNER: "name1"
        DOCUMENTS SENT
        DOCUMENTS REC'D
    TRADING PARTNER: "name2"
        DOCUMENTS SENT
        DOCUMENTS REC'D
  DATE2 ...


So, your second group will be on the pair(sen_id, rec_id). You can do that
using concat instead of union '|'
Something like: <xsl:key name="key2_name" match="header"
use="concat(date,':',sender/sen_id,' ',sender/recipient/rec_id)"/>

According to you output you want to display unique pairs so you can count
how many docs has been sent. You do this applying the second group in the
same way you applyied the first:

<xsl:apply-templates
select="key('key1_name',date)[generate-id()=generate-id('key2_name',concat(d
ate,':',sender/sen_id,' ',sender/recipient/rec_id))]"/>

(...)

The complete stylesheet:

  <xsl:key match="header" name="key1_name" use="date"/>
  <xsl:key match="header" name="key2_name"
use="concat(date,':',sender/sen_id,':',sender/recipient/rec_id)"/>
  <xsl:template match="report">
    <xsl:text>Report:&#10;</xsl:text>
    <xsl:apply-templates mode="level1"
select="header[generate-id()=generate-id(key('key1_name',date))]"/>
  </xsl:template>
  <xsl:template match="header" mode="level1">
    <xsl:text>&#160;&#160;</xsl:text>
    <xsl:value-of select="date"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:apply-templates mode="level2"
select="key('key1_name',date)[generate-id()=generate-id(key('key2_name',conc
at(date,':',sender/sen_id,':',sender/recipient/rec_id)))]"/>
  </xsl:template>
  <xsl:template match="header" mode="level2">
    <xsl:text>&#160;&#160;&#160;&#160;TRADING PARTNER: &quot;</xsl:text>
    <xsl:value-of select="sender/sen_id"/>
    <xsl:text>&quot;&#10;</xsl:text>
    <xsl:text>&#160;&#160;&#160;&#160;&#160;&#160;Documents sent </xsl:text>
    <xsl:value-of
select="count(key('key2_name',concat(date,':',sender/sen_id,'
',sender/recipient/rec_id)))"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:text>&#160;&#160;&#160;&#160;&#160;&#160;Documents REC'D
</xsl:text>
    <xsl:value-of select="sender/recipient/rec_id"/>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

Hope this helps you.



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



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



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