xsl-list
[Top] [All Lists]

Re: grouping questions

2004-08-04 09:33:24
Hi Xiang,
Please try this XSL -
(this is a Muenchian Grouping solution)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="text"/>
        
<xsl:key name="by-row" match="row"
use="concat(length,' ',Axis)" />
        
<xsl:template match="/root">
   <xsl:for-each select="Record/row[generate-id(.) =
generate-id(key('by-row', concat(length,'
',Axis))[1])]">
     Experiment (length=<xsl:value-of select="length"
/>,Axis=<xsl:value-of select="Axis"
/>)<xsl:text>&#xA;</xsl:text>
     <xsl:for-each select="key('by-row',
concat(length,' ',Axis))">
        <xsl:for-each select="*[(name() != 'length')
and (name() != 'Axis')]">
           <xsl:value-of select="name()"
/>=<xsl:value-of select="." />
             <xsl:if test="position() !=
last()">,</xsl:if>
        </xsl:for-each>
        <xsl:text>&#xA;</xsl:text>              
     </xsl:for-each>
   </xsl:for-each>
</xsl:template>
        
</xsl:stylesheet>

I added a <root> tag at the begining to make the XML
well formed.

Hope I understood the problem correctly..

Regards,
Mukul

--- Xiang Li <lix(_at_)rpi(_dot_)edu> wrote:

Hi, 

I have some problems in restructuring some data
files. what i have to do is
to group the measurements(<length>) of "a" and "c"
(<Axis>) together, so i
need to find what are the other tags in each row,
and read their values to
decide which ones belong to the same experiment. 

my xml file looks like this:

<Record sample="1">
   <row row_id='0'>
      <length>5.4</length>
      <Axis>a</Axis>
      <Environment>air</Environment>
      <Temperature>200K</Temperature>
   </row>
   <row row_id='1'>
      <length>5.3</length>
      <Axis>c</Axis>
      <Environment>air</Environment>
      <Temperature>200K</Temperature>
   </row>
   <row row_id='2'>
      <length>5.0</length>
      <Axis>a</Axis>
      <Environment>air</Environment>
      <Temperature>400K</Temperature>
   </row>
   <row row_id='3'>
      <length>5.4</length>
      <Axis>c</Axis>
      <Environment>air</Environment>
      <Temperature>400K</Temperature>
   </row>
   <row row_id='4'>
      <length>5.4</length>
      <Axis>a</Axis>
      <Environment>Ar</Environment>
      <Temperature>200K</Temperature>
   </row>
   <row row_id='5'>
      <length>5.4</length>
      <Axis>c</Axis>
      <Environment>Ar</Environment>
      <Temperature>200K</Temperature>
   </row>
</Record>
<Record sample="2">
      ...
</Record>

Problem is, tags other than <length> and <Axis> vary
from sample to sample.
this seems like impossible for me to do the grouping
using xslt. Maybe some
gurus here can give me your brilliant ideas?...
thanks!!

Xiang



                
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail


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