xsl-list
[Top] [All Lists]

RE: Sub group grouping using generate-id

2003-08-15 18:33:55
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 
Wiepert, Mathieu
Sent: Friday, August 15, 2003 10:02 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Sub group grouping using generate-id


I have tried to simplify the problem, but still have 
difficulty getting my expected results.  Given this 
simplified xml doc,

(...)

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"/>

You probably don't need the '//' here. You can use select="[your root
node]/n1:experiment" instead

      <xsl:key name="variant-key" match="//n1:variant" 
use="n1:position"/>
The xsl:key is a direct child of xsl:stylesheet, so this will give you an
error

This key will select a variant according to its child position, no matter
where it is
To select only those that belong to a certain experiment you'll have to had
that to the key
Something like:
<xsl:key name="variant-key" match="n1:variant"
use="concat(generate-id(ancestor::n1:experiment),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])]"/>

This variable will never select anything. The key is matching n1:variant and
you are comparing it to n1:position, so, generate-id(n1:variant) will always
be different from generate-id(n1:position)
Your variable is also selecting all n1:variant of the document, you only
want those the are descendant of the current experiment. To select those you
can use descendant::n1:variant or, using its path,
n1:genotypesInSubject/n1:pcrResuts/n1:variant

The variable definition will be:
<xsl:variable name="unique-exp-variants"
select="n1:genotypesInSubject/n1:pcrResuts/n1:variant[generate-id()=generate
-id(key('variant',concat(generate-id(current()),n1:position)))]"/>

(...)

Regards,
Americo Albuquerque


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



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