Subject: RE: [xsl] How to get elements in a row? From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx> Date: Thu, 17 Jan 2002 10:57:35 -0000 |
Hi, Try this piece of xslt from a fellow newbie: <xsl:template match="item"> <xsl:value-of select="ancestor::sample/name"/> <xsl:text>, </xsl:text> <xsl:value-of select="name"/> <xsl:for-each select="features/feature"> <xsl:text>, </xsl:text> <xsl:value-of select="name"/> </xsl:for-each> <br/> </xsl:template> <xsl:template match="/"> <xsl:apply-templates select="//items/item"/> </xsl:template> produces: sample1, item1, one, two sample1, item2, three, four There will be other better solutions, but this should help cheers andrew === -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Marko.Seppala@xxxxxxxx Sent: Thursday, January 17, 2002 10:20 AM To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] How to get elements in a row? Hi, How I can get elements in a comma separated row without last comma and header line? Each item should have its features (one, two, three, four) but also its parent (sample1). I am using xalan java processor 2.2.d13. Wanted Output ****************************************************** sample1,item1,one,two sample1,item2,three,four ****************************************************** Current Output ****************************************************** <?xml version="1.0" encoding="UTF-8"?> sample1, item1, one, two, item2, three, four, ****************************************************** XML ****************************************************** <?xml version="1.0" encoding="UTF-8"?> <samples> <sample id = "1"> <name>sample1</name> <items> <item id = "1"> <name>item1</name> <features> <feature id = "1"> <name>one</name> </feature> <feature id = "2"> <name>two</name> </feature> </features> </item> <item id = "12"> <name>item2</name> <features> <feature id = "3"> <name>three</name> </feature> <feature id = "4"> <name>four</name> </feature> </features> </item> </items> </sample> </samples> ****************************************************** XSL ****************************************************** <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="samples"> <xsl:apply-templates select="sample"/> </xsl:template> <xsl:template match="sample"> <xsl:apply-templates select = "name"/> <xsl:apply-templates select = "items"/> </xsl:template> <xsl:template match="items"> <xsl:apply-templates select="item"/> </xsl:template> <xsl:template match="item"> <xsl:apply-templates select = "name"/> <xsl:apply-templates select = "features"/> </xsl:template> <xsl:template match="features"> <xsl:apply-templates select="feature"/> </xsl:template> <xsl:template match="feature"> <xsl:apply-templates select = "name"/> </xsl:template> <xsl:template match="name"> <xsl:value-of select = "."/>, </xsl:template> </xsl:stylesheet> ****************************************************** Thanks in advance! Marko XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to get elements in a row?, Marko . Seppala | Thread | RE: [xsl] How to get elements in a , Elovirta Jarno (NBI/ |
Re: [xsl] xhtml DOCTYPE problem, Steven Noels | Date | [xsl] Problem with Jaxen, Jakub . Valenta |
Month |