xsl-list
[Top] [All Lists]

Sub group grouping using generate-id

2003-08-15 14:01:48
I have tried to simplify the problem, but still have difficulty getting my 
expected results.  Given this simplified xml doc,

<experiment>
  <genotypesInSubject>
    <id>1</id>
    <pcrResuts>
      <variant>
         <position>1</position>
      </variant>
      <variant>
         <position>2</position>
      </variant>
    </pcrResuts>
  </genotypesInSubject>
  <genotypesInSubject>
    <id>2</id>
    <pcrResuts>
      <variant>
         <position>1</position>
      </variant>
      <variant>
         <position>2</position>
      </variant>
      <variant>
         <position>3</position>
      </variant>
    </pcrResuts>
  </genotypesInSubject>
</experiment>
<experiment>
  <genotypesInSubject>
    <id>1</id>
    <pcrResuts>
      <variant>
         <position>1</position>
      </variant>
      <variant>
         <position>2</position>
      </variant>
      <variant>
         <position>4</position>
      </variant>
    </pcrResuts>
  </genotypesInSubject>
  <genotypesInSubject>
    <id>2</id>
    <pcrResuts>
      <variant>
         <position>1</position>
      </variant>
      <variant>
         <position>2</position>
      </variant>
      <variant>
         <position>3</position>
      </variant>
    </pcrResuts>
  </genotypesInSubject>
</experiment>

During processing, if I am at a given <experiment> node, how do I get a 
variable holding unique variant nodes, as classified by the <position> element? 
 Or put another way, how do I get a list of <variant>'s unique to an 
<experiment> node, using the <position> child element of <variant> as the key?

Expected results would be
experiment node 1 has variant at position1,2, and 3
experiment node 2 has variant at position 1,2,3, and 4

I have been trying to get this filled in but have been spectacularly 
unsuccessful.

Here is one of the very many attempts...

<xsl:template match="/">
        <xsl:variable name="expNodes" select="//n1:experiment"/>
        <xsl:key name="variant-key" match="//n1:variant" use="n1:position"/>
        .
        .
        <xsl:for-each select="$expNodes">
                <xsl:variable name="unique-exp-variants" 
select="//n1:variant[generate-id(//n1:position)=generate-id(key('variant-key',.)[1])]"/>
                .
                .

Any hints would be appreciated,

thanks
-mat




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



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