Subject: RE: [xsl] transforming from flat to hierarchical "grouping" From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx> Date: Wed, 18 Apr 2001 16:40:31 +0300 |
Hip hei! > Nowhere are the possible values of the "category" attribute defined. Each > source XML is allowed to use any number of category values (and have any > number of articles) but each article has only one category > attribute value. > I'm using XT. How about [c:\temp]type test.xml <?xml version="1.0" encoding="ISO-8859-1"?> <articles> <article category="news">foo1</article> <article category="news">foo2</article> <article category="sports">foo3</article> <article category="news">foo4</article> <article category="sports">foo5</article> <article category="local">foo6</article> </articles> [c:\temp]type test.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <!-- Select every article which is not preceded by an article with of same category, i.e. the first of every category --> <xsl:apply-templates select="descendant::article[not(@category = preceding::article/@category)]" /> </xsl:template> <xsl:template match="article"> <xsl:element name="{@category}"> <!-- Process the current article, which is the first of that category and all following ones, too --> <xsl:for-each select=". | following::article[@category = current()/@category]"> <article> <xsl:apply-templates /> </article> </xsl:for-each> </xsl:element> </xsl:template> </xsl:stylesheet> [c:\temp]xt test.xml test.xsl <?xml version="1.0" encoding="utf-8"?> <news> <article>foo1</article> <article>foo2</article> <article>foo4</article> </news> <sports> <article>foo3</article> <article>foo5</article> </sports> <local> <article>foo6</article> </local> You should use preceding-sibling and following-sibling axis if you can, faster that way. There are people on this list who will give you a better solution. Jarno - Assemblege 23: Love My Way (Psychadelic Furs cover) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] transforming from flat to hie, by way of Mulberry T | Thread | RE: [xsl] transforming from flat to, Michael Kay |
RE: [xsl] xml too big, Jarno Elovirta | Date | [xsl] Copying of nodes, Martin Renner |
Month |