Solved

Muenchian grouping and knowing selects inside a group

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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