[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: transforming from flat to hierarchical "grouping"

Subject: RE: transforming from flat to hierarchical "grouping"
From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx>
Date: Wed, 18 Apr 2001 16:40:31 +0300
companies transforming to flat
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.