Solved

Muenchian grouping and knowing selects inside a group

Posted on 2006-11-21
2
262 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML template problem 4 66
C# Modify Read / Write / Update / Delete to  XML 2 59
RSS Feed Parsing for Images 5 59
Unable to resolve XML http request 4 75
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, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now