[xsl] Combining grouping and generate-id() for multilevel TOC

Subject: [xsl] Combining grouping and generate-id() for multilevel TOC
From: Ghostrider <ghostrider@xxxxxxxxxxx>
Date: Wed, 18 Jul 2001 10:01:46 +0200

I've been trying to generate a two-level TOC in my HTML output, entries 
linking to anchors created with a generate-id(). It works for the first, top 
level but I can't get the second level from the hierarchy in there properly...

Could someone maybe have a look if my problem is the same as the one Jeni 
solved in this message: 
http://www.biglist.com/lists/xsl-list/archives/200101/msg00149.html ? 
I can't seem to transform her templates and stuff to fit my situation (which, 
unfortunately, is the way I have to go about using XSL...).

Am I correct if I assume that I need to 
1. add a second grouping in the xsl for that second level, like I did for the 
first one, and
2. use another generate-id() to refer to all these second level groups with a 
unique anchor?

If so, how do I go about this? I'm having trouble putting the pieces together 
logically, so any help would be appreciated.



<--=========== desired HTML output file: first grouping by <Category 1> 
elements, then by <Category2>, both in the TOC section and in the Release 
Notes section with the actual content in it ================-->


--- <a href="#0123456"> DPF </a>
--- IPC
--- DPF
--- IPC


--- <a name="0123456'>DPF - Description 1<a>
--- IPC - Description 2
--- DPF - Description 3
--- IPC - Description 4

<--=============== XML source ==========================-->

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" 

			<Category1>Input</Category1> <-- grouping for Category1 is OK in XSL -->
			<Category2>DPF</Category2> <-- additional (sub)grouping for Category2 is 
not OK yet -->
			<Type>Bug fix</Type>
			<Description>Reading in ODB++ somehow ...</Description>

			<Description>Reading in ODB++ somehow ...</Description>

			<Description>Reading in ODB++ somehow ...</Description>



		<Call BugBase="001"> B10015 </Call>
		<Call BugBase="001"> B10016 </Call>
		<Call BugBase="002"> B10017 </Call>
		<Call BugBase="003"> B10018 </Call>
		<Call BugBase="003"> B10019 </Call>



<--=============== XSL stylesheet ======================-->

<xsl:stylesheet version="1.0" 
<xsl:key name="categories" match="Bug" use="Category1"/>
<xsl:key name="categories2" match="Bug" use="concat (Category1, ' 
',Category2)" />
<xsl:key name="calls" match="Call" use="@BugBase"/>

<xsl:template match="root">
<p>Release Notes</p>

<!-- TOC start-->

<p><b>Table of Contents</b></p>
<xsl:for-each select="//Bug[generate-id(.) = generate-id(key ('categories', 
Category1) [1] ) ]">
<a href="#{generate-id(.)}"><xsl:value-of select="Category1" /> </a>
  <br />


<!-- TOC end-->

<!-- Bug fix start-->

<xsl:apply-templates />

<!-- Bug fix end-->



<xsl:template match="root/Bugs">
<xsl:apply-templates select="Bug[generate-id(.) = generate-id(key 
('categories', Category1) [1] ) ]" />

<xsl:template match="Bugs/Bug">

<b><a name="{generate-id(.)}"><xsl:value-of select="Category1" /></a></b>
<xsl:for-each select="key('categories', Category1)">

<span style="color:maroon;font-size:10pt;">
<p style="font-family:verdana,arial, helvetica, sans-serif;font-weight:bold">
<a name="Type"></a></p>
<b><xsl:value-of select="Category2"/></b></p>

<p<xsl:for-each select="key('calls', BugBase)">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">, </xsl:if>
<xsl:value-of select="Description"/>
<!--Start: no output for Call node-->
<xsl:template match="root/Calls/Call">
<!--End: no output for Call node-->


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread