Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Question about create pivot table in xslt [Thread Next] Re: Question about create pivot table in xsltTo: NULL Date: 6/2/2007 12:43:00 AM On Jun 1, 11:33 am, Lee <lee.jenkins...@gmail.com> wrote: > On Jun 1, 5:59 am, "Dimitre Novatchev" <dimit...@tpg.com.au> wrote: > > > > > > > See: > > > http://www.topxml.com/code/default.asp?p=3&id=v20010226151246 > > > Cheers, > > Dimitre Novatchev > > > "Lee" <lee.jenkins...@gmail.com> wrote in message > > >news:1180653377.445712.231260@p...... > > > >I have a xml file, here is sample part: > > > <?xml version="1.0" encoding="UTF-8"?> > > > <ProducsList> > > > <Product id="1"> > > > <SpecList> > > > <Spec> > > > <SpecLabel>Height</SpecLabel> > > > <SpecValue>10</SpecValue> > > > <SpecCat>Dimension</SpecCat> > > > </Spec> > > > <Spec> > > > <SpecLabel>Width</SpecLabel> > > > <SpecValue>6</SpecValue> > > > <SpecCat>Dimension</SpecCat> > > > </Spec> > > > <Spec> > > > <SpecLabel>Weight</SpecLabel> > > > <SpecValue>20.5</SpecValue> > > > <SpecCat>Weigth</SpecCat> > > > </Spec> > > > </SpecList> > > > </Prodcut> > > > <Product id="2"> > > > <SpecList> > > > <Spec> > > > <SpecLabel>Height</SpecLabel> > > > <SpecValue>8</SpecValue> > > > <SpecCat>Dimension</SpecCat> > > > </Spec> > > > <Spec> > > > <SpecLabel>Width</SpecLabel> > > > <SpecValue>5</SpecValue> > > > <SpecCat>Dimension</SpecCat> > > > </Spec> > > > <Spec> > > > <SpecLabel>Weight</SpecLabel> > > > <SpecValue>18</SpecValue> > > > <SpecCat>Weigth</SpecCat> > > > </Spec> > > > </SpecList> > > > </Prodcut> > > > <Product id="3"> > > > <SpecList> > > > <Spec> > > > <SpecLabel>Height</SpecLabel> > > > <SpecValue>5</SpecValue> > > > <SpecCat>Dimension</SpecCat> > > > </Spec> > > > <Spec> > > > <SpecLabel>Width</SpecLabel> > > > <SpecValue>2</SpecValue> > > > <SpecCat>Dimension</SpecCat> > > > </Spec> > > > <Spec> > > > <SpecLabel>Weight</SpecLabel> > > > <SpecValue>10</SpecValue> > > > <SpecCat>Weigth</SpecCat> > > > </Spec> > > > </SpecList> > > > </Prodcut> > > > </ProductsList> > > > > I need to create a table look like that based on that xml file: > > > > ---------------------------------------------------- > > > Label Product 1 product 2 product 3 > > > ---------------------------------------------------- > > > Height 10 8 5 > > > Width 6 5 2 > > > Weight 20.5 18 10 > > > > I am totally losed, I don't know how to create that table. any one has > > > any idea about that? thank you very much. > > > > Also how many Spec in SpecList is unkown. > > > > Thanks for the help.- Hide quoted text - > > > - Show quoted text - > > Dimitre, > > I found you are using msxsl namespace, is that gonna be a problem for > none-microsoft browsers? Thanks.- Hide quoted text - > > - Show quoted text - Thank you guys, I finially figured out how to do it. at the very beginning I thought I can't use param in for-each, so I don't event try to use variable, acutually, variable is OK to use in for-each loop. so my xslt file is here: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform"> <xsl:output method="html" /> <xsl:template match="/"> <html> <body> <table border="1"> <xsl:for-each select="/ProductList/Product[position()=1]/SpecList/ Spec"> <xsl:variable name="label" select="SpecLabel"></xsl:variable> <tr> <td> <xsl:value-of select="$label"/> </td> <xsl:for-each select="/ProductList/Product"> <td> <xsl:apply-templates select="SpecList/Spec/SpecLabel[.= $label]"/> </td> </xsl:for-each> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="SpecLabel"> <xsl:value-of select="../SpecValue"/> </xsl:template> </xsl:stylesheet> | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
