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

two level grouping

Subject: two level grouping
From: "Martina Kinzl" <Martina.Kinzl@xxxxxxxxxx>
Date: Thu, 12 Aug 2004 12:10:51 +0200
ius civile
Hi there,

I am trying to create an index of keywords of my online-book.
My source XML-file contains a lot of keywords which are more specified with
Elements (Level1 or even Level2):

<Stichwortliste>
<Stichwortdetails>
	<Stichwort>
		<Level1>ius civile</Level1>
		<Titel titel_id="CBAHDGEI">B|rgerliches Recht, Zivilrecht,
ius civile</Titel>
		<Kapitel>kap1_1.xml</Kapitel>
	</Stichwort>
	<Stichwort>
		<Level1>Privatrecht</Level1>
		<Titel titel_id="CBAHDGEI">B|rgerliches Recht, Zivilrecht,
ius civile</Titel>
		<Kapitel>kap1_1.xml</Kapitel>
	</Stichwort>
	<Stichwort>
		<Level1>Privatrecht</Level1>
		<Level2>allgemeines</Level2>
		<Titel titel_id="CBAHDGEI"> Recht im objektiven und
subjektiven Sinn</Titel>
		<Kapitel>kap2_4.xml</Kapitel>
	</Stichwort>
	<Stichwort>
		<Level1>Privatrecht</Level1>
		<Titel titel_id="CBAHDGEI"> Das Gesamtrechtssystem </Titel>
		<Kapitel>kap5_3.xml</Kapitel>
	</Stichwort>
</Stichwortdetails>
<Stichwortliste>


I would like to have the following output:

The keywords are sorted alphabetically and if there are more keywords that
are equal the name of the keyword should be printed once and the
chapter-specifications should follow. And if there are keywords that own the
more specified Level2 then these keywords (+chapter-specifications) should
not be given out until all the keywords (only with Level1-elements of the
same name) have been printed out.

Here is what I have:

I
ius civile [kap1_1]

P
Privatrecht [kap1_1],
	allgemeines [kap2_4], [kap5_3]


Here is what I would like to have:

I
Ius civile [kap1_1]

P
Privatrecht [kap1_1], [kap5_3]
	allgemeines [kap2_4]


Here is my XSL:

<xsl:key name="keyword-initial" match="Stichwort"
use="translate(substring(Level1,1,1),'abcdefghijklmnopqrstuvwxyzdv|123456789
0@','ABCDEFGHIJKLMNOPQRSTUVWXYZDV\###########')"/>
<xsl:key name="contacts-by-surname" match="Stichwort" use="Level1"/>
<xsl:template match="Stichwortdetails">

	<xsl:for-each select="Stichwort[count(. | key('keyword-initial',
translate(substring(Level1,1,1), 'abcdefghijklmnopqrstuvwxyzdv|1234567890@',
'ABCDEFGHIJKLMNOPQRSTUVWXYZDV\###########'))[1]) = 1]">
		<xsl:sort select="Level1"/>
		<xsl:variable name="initial"
select="translate(substring(Level1,1,1),
'abcdefghijklmnopqrstuvwxyzdv|1234567890@',
'ABCDEFGHIJKLMNOPQRSTUVWXYZDV\###########')"/>
		<a name="{$initial}"/>
			<div><xsl:value-of select="$initial"/></div>
			<ul>
				<xsl:for-each select="key('keyword-initial',
$initial)">
					<xsl:sort select="Level1"/>
					<xsl:if test="count(. |
key('contacts-by-surname', Level1)[1]) = 1">
						<br/>
						<span><xsl:value-of
select="Level1"/></span>
					</xsl:if>
                    				    <xsl:if
test="not(name(Level1/following-sibling::*) = 'Level2')">
					            	<span
style="color:green;"><xsl:apply-templates select="Level1"
mode="index.link"/></span>
                    				    </xsl:if>
				    <xsl:for-each select="Level2">
						<xsl:sort select="Level2"/>
						<br/>
						<span style="color:red;
margin-left:20px;"><xsl:apply-templates select="."
mode="index.link"/></span>
					</xsl:for-each>
				</xsl:for-each>
			</ul>
			<br/>
	</xsl:for-each>
</xsl:template>


It seems that the second for-each-loop <xsl:for-each select="Level2"> isnt
correct, but I dont know how to do it right.
It must be something like a grouping within a grouping?!?
Can you give me any advice?

Thanks
Martina

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.