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

Re: RE: flat structure to deep structure in a smart wa

Subject: Re: RE: flat structure to deep structure in a smart way
From: <jozef.aerts@xxxxxxxxxxxxxx>
Date: Fri, 24 Sep 2004 21:40:02 +0200
flat structure
Dear Michael,

Many thanks for the link. The article is a real eye-opener.

So I started:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:key name="A-key" match="line" use="item[@itemcount=1]"/>
	<xsl:key name="B-key" match="line" use="item[@itemcount=2]"/>
	<xsl:key name="C-key" match="line" use="item[@itemcount=3]"/>
	
	<xsl:template match="root">
	  <xsl:element name="result">
	    <xsl:for-each select="line[count(. | key('A-key',
item[@itemcount=1])[1]) = 1]">
	      <xsl:element name="A">
	        <xsl:attribute name="Value"><xsl:value-of
select="item[@itemcount=1]" /></xsl:attribute>
	        <xsl:for-each select="key('A-key', item[@itemcount=1])">
	            <!-- we need to group the B-elements 
	            How do we do that here ? -->
	            <xsl:element name="B">
	              <xsl:attribute name="Value"><xsl:value-of
select="item[@itemcount=2]"/></xsl:attribute>
	            </xsl:element>
	          </xsl:for-each>
	      </xsl:element>
	     </xsl:for-each>
	   </xsl:element>
	</xsl:template>
</xsl:stylesheet>

which brings me:

<?xml version="1.0" encoding="UTF-8"?>
<result>
	<A Value="A1">
		<B Value="B1"/>
		<B Value="B22"/>
	</A>
	<A Value="A3">
		<B Value="B3"/>
		<B Value="B3"/>
		<B Value="B3"/>
	</A>
</result>

Now I got a bit stuck. Under the A3 I need to group the B-elements
again. How do I do that ?
I presume I need to change/add something to the 
<xsl:for-each select="key('A-key', item[@itemcount=1])"> line
but it is not entirely clear how to do that.

P.S. Once this is solved I will post the full stylesheet as I think this
a very typical problem from a sorted database table.

Many thanks in advance

Jozef


Michael Kay <mike@xxxxxxxxxxxx> schrieb am 24.09.2004, 19:22:44:
> > In the element  you see an A1 again, so B22 
> > should fall
> > under A1 that's under line 1. I.e. if an element has the same value as
> > in the previous line, it should become a subelement of the first line.
> > 
> > 
> > What is the best strategy to accomplish this ?
> > 
> 
> As mentioned several times in the last couple of days, read
> 
> http://www.jenitennison.com/xslt/grouping
> 
> Michael Kay
> http://www.saxonica.com/

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.