Re: [xsl] grouping questions

Subject: Re: [xsl] grouping questions
From: Xiang Li <lix@xxxxxxx>
Date: Wed, 04 Aug 2004 14:36:40 EDT
Hi, Mukul,

Thanks for your reply. I guess I did not explain the problem well in my
last message, actually i wanted to put togther row[Axis='c'] and
row[Axis='a'] according to their experimental conditions, so that i can use
their <length> values to do some calculations. and the grouping is done
within each <Sample> element.

so my output file should look like:

<root>
 <Sample label="1">
   <Record>
     <Ratio_A_by_C>1.02</Ratio_A_by_C> <!--length of 'a' divided by length
of 'c' -->
     <ExperimentalConditions>
       <atmosphere>air</atmosphere>
       <temperature>200K</temperature>
     </ExperimentalConditions>
   </Record>
   <Record>
     <Ratio_A_by_C>0.93</Ratio_A_by_C>
     <ExperimentalConditions>
       <atmosphere>air</atmosphere>
       <temperature>400K</temperature>
     </ExperimentalConditions>>
   </Record>
   <Record>
     <Ratio_A_by_C>1.0</Ratio_A_by_C>
     <ExperimentalConditions>
       <atmosphere>Ar</atmosphere>
       <temperature>200K</temperature>
     </ExperimentalConditions>
   </Record>
  </Sample>
 <Sample label="2">
   <Record>
     <Ratio_A_by_C>1.15</Ratio_A_by_C>
     <ExperimentalConditions>
       <atmosphere>air</atmosphere>
       <temperature>200K</temperature>
     </ExperimentalConditions>
   </Record>
 ...
 ...
 </Sample>
</root>

one additional problem is that the experimental condition tags
(temperature, are not always the same.

Appreciate your help!

Xiang


On Wed, 4 Aug 2004 09:33:24 -0700 (PDT) Mukul Gandhi wrote:

> 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>
</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>
</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@xxxxxxx> 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

Current Thread