Solved

Muenchian grouping and knowing selects inside a group

Posted on 2006-11-21
2
272 Views
Last Modified: 2012-06-21
Hello experts,

I've had good advice re: grouping already, and below I've worked it OK for strains, but I just can't get (the correct) multiple rows per expt/strain combination! I guess I'm still not understanding completely. I would ideally like a good explaination of how/why a solution works because I really need to learn fully for myself.

I've included my desired result along with the xml & xsl below. What I get is all the plates for the current experiment listed under each strain, instead of just the ones for that strain.

Many thanks,

Gary

--------desired result--------

22303
  TA 100
    162, 37, 180
    109, 130, 145
  TA 102
    8, 48, 196
    65, 27, 84
22304
  TA 100
    179, 168, 3
    35, 9, 161
  TA 102
    15, 196, 146
    26, 81, 60

--------xml--------

<PLATE_SUMMARY>
  <EXPT_ID>22303</EXPT_ID>
  <STRAIN_CODE>TA 100</STRAIN_CODE>
  <COUNTS>162, 37, 180</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22303</EXPT_ID>
  <STRAIN_CODE>TA 100</STRAIN_CODE>
  <COUNTS>109, 130, 145</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22303</EXPT_ID>
  <STRAIN_CODE>TA 102</STRAIN_CODE>
  <COUNTS>8, 48, 196</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22303</EXPT_ID>
  <STRAIN_CODE>TA 102</STRAIN_CODE>
  <COUNTS>65, 27, 84</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22304</EXPT_ID>
  <STRAIN_CODE>TA 100</STRAIN_CODE>
  <COUNTS>179, 168, 3</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22304</EXPT_ID>
  <STRAIN_CODE>TA 100</STRAIN_CODE>
  <COUNTS>35, 9, 161</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22304</EXPT_ID>
  <STRAIN_CODE>TA 100</STRAIN_CODE>
  <COUNTS>123, 178, 30</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22304</EXPT_ID>
  <STRAIN_CODE>TA 102</STRAIN_CODE>
  <COUNTS>15, 196, 146</COUNTS>
</PLATE_SUMMARY>
<PLATE_SUMMARY>
  <EXPT_ID>22304</EXPT_ID>
  <STRAIN_CODE>TA 102</STRAIN_CODE>
  <COUNTS>26, 81, 60</COUNTS>
</PLATE_SUMMARY>

--------xsl--------

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:key name="EXPT" match="PLATE_SUMMARY" use="EXPT_ID"/>
<xsl:key name="STRAIN" match="PLATE_SUMMARY" use="STRAIN_CODE"/>
<!--ROOT TEMPLATE-->
<xsl:template match="/">
<html>
<head>
  <title>Study <xsl:value-of select="STUDY/STUDY_CODE" /></title>
</head>
<body>
  <xsl:for-each select="/STUDY/PROCESSED_DATA/PLATE_SUMMARY[generate-id() = generate-id(key('EXPT',EXPT_ID)[1])]">
    <h1><xsl:value-of select="EXPT_ID" /></h1>
    <xsl:for-each select="/STUDY/PROCESSED_DATA/PLATE_SUMMARY[generate-id() = generate-id(key('STRAIN',STRAIN_CODE)[1])]">
      <h2><xsl:value-of select="STRAIN_CODE" /></h2>
      <table border="1">
        <thead>
          <tr>
            <td>COUNTS</td>
          </tr>
        </thead>
        <xsl:for-each select="-------!!!!I DON'T KNOW!!!!-------">
          <tr>
            <td><xsl:value-of select="COUNTS" /></td> <!--SHOULD GET MULTIPLE ROWS HERE SPECIFIC TO CURRENT EXPT & STRAIN-->
          </tr>
        </xsl:for-each>
      </table>
    </xsl:for-each>
  </xsl:for-each>
</body>
</html>
</xsl:template>

0
Comment
Question by:theskintman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17986616
Hi theskintman,

Here is your XSLT
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:key name="EXPT" match="PLATE_SUMMARY" use="EXPT_ID"/>
    <xsl:key name="STRAIN" match="PLATE_SUMMARY" use="STRAIN_CODE"/>
    <!--ROOT TEMPLATE-->
    <xsl:template match="/">
        <html>
            <body>
                <xsl:for-each select="//PLATE_SUMMARY[generate-id() = generate-id(key('EXPT',EXPT_ID)[1])]">
                    <h1><xsl:value-of select="EXPT_ID" /></h1>
                    <xsl:variable name="thisExpt" select="EXPT_ID"></xsl:variable>
                    <xsl:for-each select="//PLATE_SUMMARY[generate-id() = generate-id(key('STRAIN',STRAIN_CODE)[EXPT_ID = $thisExpt][1])]">
                        <h2><xsl:value-of select="STRAIN_CODE" /></h2>
                        <table border="1">
                            <thead>
                                <tr>
                                    <td>COUNTS</td>
                                </tr>
                            </thead>
                            <xsl:for-each select="key('STRAIN',STRAIN_CODE)[EXPT_ID = $thisExpt]">
                                <tr>
                                    <td><xsl:value-of select="COUNTS" /></td>
                                </tr>
                            </xsl:for-each>
                        </table>
                    </xsl:for-each>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
    </xsl:stylesheet>

Cheers!
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 400 total points
ID: 17986670
theskintman,

you were almost there, and you seem to understand Muenchian OK.
It is a bit trickier if you are dealing with double keys and nested loops

- first you have to know that your outer loop creates a context of PLATE_SUMMARY
    so this <xsl:for-each select="/STUDY/PROCESSED_DATA/...
    can not work, since you don't have STUDY inside PLATE_SUMMARY
    note that I used <xsl:for-each select="//PLATE_SUMMARY[....  to start at the document root again,
    if that is not possible because you have to stay in a certain scope, you can change that to
    <xsl:for-each select="../PLATE_SUMMARY[

- using key(), you use the index of the entire series of PLATE_SUMMARY,
    that is why you have to repeat the EXPT_ID condition
    here is how to do that [generate-id() = generate-id(key('STRAIN',STRAIN_CODE)[EXPT_ID = $thisExpt][1])]">
    I use the same trick as the outer loop, but I added [EXPT_ID = $thisExpt][1] inside the generate-id
    so I am taking the first PLATE_SUMMARY that has this specific EXPT_ID and STRAIN_CODE
    here is your nested grouping solved

- now about repeating over the elements that have the same EXPT_ID and STRAIN_CODE
    I use the same technique, note that key() returns a nodeset that you can further restrict
    <xsl:for-each select="key('STRAIN',STRAIN_CODE)[EXPT_ID = $thisExpt]">

As you see, explanation is easy, because you were almost there

For explaining the Muenchian in general, I still thinks Teni's web reference says it all

cheers

Geert
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question