[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] grouping questions


Subject: Re: [xsl] grouping questions
From: Xiang Li <lix@xxxxxxx>
Date: Thu, 05 Aug 2004 10:05:59 EDT

Hi, Mukul,

Thank you again for the XSL file. now i have one more question left, if in
the original file, rows of "c" are not always the
"following-sibling::row[1]" to the corresponding "a" row, is there any way
to find it? the reason i asked this question is, I got the original data
from different sources, and there are lots of problems with the original
data.

Regards,
Xiang

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

> Hi Xiang,
>   Please try this XSL -
> 
> <?xml version="1.0"?> 
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>  
> <xsl:output method="xml" indent="yes" /> 
>  
> <xsl:decimal-format name="fmt" digit="D" />
> 
> <xsl:template match="/root">
>   <root>
>    <xsl:for-each select="Record">
>     <Sample label="{@sample}">
>      <xsl:for-each select="row[Axis = 'a']">
>	<Record>
>	 <Ratio_A_by_C>
>	   <xsl:value-of select="format-number(length
> div following-sibling::row[1]/length, 'DDDD.DD',
> 'fmt')" />
>	 </Ratio_A_by_C>
>	 <ExperimentalConditions>
>	    <xsl:for-each select="*[(name() != 'Axis')
> and (name() != 'length')]">
>	      <xsl:element name="{name()}">
>		<xsl:value-of select="." />
>	      </xsl:element>
>	    </xsl:for-each>
>	 </ExperimentalConditions>
>	</Record>
>      </xsl:for-each>
>     </Sample> 
>    </xsl:for-each>
>   </root> 
> </xsl:template>
>   
> </xsl:stylesheet>
> 
> Regards,
> Mukul
> 
> --- Xiang Li <lix@xxxxxxx> wrote:
> 
> > 
> > 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!?
> New and Improved Yahoo! Mail - Send 10MB messages!
> http://promotions.yahoo.com/new_mail 


Current Thread
Keywords