[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Multi-grouping with keys (back of book index)


Subject: Re: [xsl] Multi-grouping with keys (back of book index)
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sun, 22 Oct 2006 14:41:06 +0530

I guess, your manuals meta-data is organized as follows:

Let this file be named as manuals.xml (which you provide to the
stylesheet as input).

<manuals>
 <manual>
    <title>MelChapter1.xml</title>
    <title>Chapter9a.xml</title>
    ...
 </manual>
 <manual>
    <title>xx1.xml</title>
    <title>xx2.xml</title>
    ...
 </manual>
 ...
</manuals>

Now in the stylesheet, you could do:

<xsl:variable name="temp">
 <xsl:for-each select="//title">
    <xsl:copy-of select="document({.})//indexterm" />
 </xsl:for-each>
</xsl:variable>

<xsl:for-each-group select="$temp//indexterm"
group-by="substring(@name,1,1)">
... rest of the logic will be same

(this is not tested)

On 10/22/06, Philip Vallone <philip.vallone@xxxxxxxxxxx> wrote:
Hi guys, I have another question. If I wanted to process many XML files I
will need to add the document() function. The end result of all this would
be a master index. I have many manuals, each chapter is its own XML file,
so
I would like to have one XML file process many XML files and creates one
master index file.

I am not sure how to go about it. Should I use a Key to index all the
indexterms from all the XML files?

Here is my XML file list all the chapters that need to be combined into one
index:

<manual>
       <title>MelChapter1.xml</title>
       <title>Chapter9a.xml</title>
</manual>

Each XML file will have something like this:

<book>
<indexterm name="GMM">Aircraft Logbook Entry</indexterm>
<indexterm name="Smith Airways">MEL Policy and Revision number</indexterm>
<indexterm name="GMM">MX-4 Deffered Items</indexterm>
<indexterm name="E190">Aircraft Tail</indexterm>
<indexterm name="E190">Landing Gear</indexterm>
<indexterm name="Election">Voting</indexterm>
</book>


Here is my XSLT so far with the added Document function. All it does is
loop
through each XML but doesn't group all the indexterms into one:

       <xsl:output method="html"/>
       <xsl:variable name="XML1" select="/"/>
       <xsl:template match="/">
               <html>
                       <head>
                               <title>Manual Index</title>
                       </head>
                       <body>
                               <a name="top"/>
                               <xsl:for-each select="$XML1">
                                       <xsl:for-each select="manual">
                                               <xsl:for-each
select="title">
                                                       <xsl:variable
name="thetitle" select="."/>
                                                       <xsl:for-each-group
select="document($thetitle)//indexterm" group-by="substring(@name,1,1)">
                                                               <xsl:sort
select="@name"/>

<xsl:variable name="book" select="@bookmark"/>
                                                               <h1>

<xsl:value-of select="current-grouping-key()"/>
                                                               </h1>
                                                               <span
style="font-size:xx-small; color:lightgray; ">
                                                                       <p
align="right">

<a href="#top">[Return to Top]</a>
                                                                       </p>
                                                               </span>

<xsl:for-each-group select="current-group()" group-by="@name">

<span style="color:blue;">

<xsl:value-of select="current-grouping-key()"/>

</span>

<xsl:for-each select="current-group()">

<xsl:sort select="."/>

<ul>

<span style="font-size:x-small;">

<a href="{$thetitle}{'#'}{$book}">

<xsl:value-of select="."/>

</a>

</span>

</ul>

</xsl:for-each>

</xsl:for-each-group>

</xsl:for-each-group>
                                               </xsl:for-each>
                                       </xsl:for-each>
                               </xsl:for-each>
                       </body>
               </html>
       </xsl:template>

Thanks Again,

Phil

-----Original Message-----
From: philip vallone [mailto:philip.vallone@xxxxxxxxxxx]
Sent: Saturday, October 21, 2006 4:06 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Multi-grouping with keys (back of book index)

Thanks for the help. This works great in 2.0. I was originally using the
Muenchian method because I was using MSXML with Internet Explorer to
process. This is much easier.

Here is what I used to output to HTML:

Once again...Thanks


<xsl:template match="/"> <html> <head> <title>Manual Index</title> </head> <style type="text/css"> h2 {font-family:verdana,helvetica,sans-serif;font-size:13pt} li {font-family:verdana,helvetica,sans-serif;font-size:11pt} </style> <body> <xsl:for-each select="$XML1"> <xsl:for-each-group select="//indexterm" group-by="substring(@name,1,1)"> <xsl:sort select="@name"/> <h1> <xsl:value-of select="current-grouping-key()"/> </h1> <xsl:for-each-group select="current-group()" group-by="@name"> <span style="color:blue;">

<xsl:value-of select="current-grouping-key()"/>
                                                       </span>
                                                       <xsl:for-each
select="current-group()">
                                                               <xsl:sort
select="."/>
                                                               <ul>

<span style="font-size:x-small;">

<xsl:value-of select="."/>

</span>
                                                               </ul>
                                                       </xsl:for-each>
                                               </xsl:for-each-group>
                                       </xsl:for-each-group>
                               </xsl:for-each>
                       </body>
               </html>
       </xsl:template>



-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx]
Sent: Saturday, October 21, 2006 3:08 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Multi-grouping with keys (back of book index)


As I see it you are using XSLT 1 techniques in an XSLT 2 stylesheet when XSLT 2 already gives you what you need as native constructs.

I hope the following use of XSLT 2 facilities helps.

. . . . . . . . . Ken

T:\ftemp>type philip.xml
<book>
<indexterm name="GMM">Aircraft Logbook Entry</indexterm>
<indexterm name="Smith Airways">MEL Policy and Revision number</indexterm>
<indexterm name="GMM">MX-4 Deffered Items</indexterm>
<indexterm name="E190">Aircraft Tail</indexterm>
<indexterm name="E190">Landing Gear</indexterm>
<indexterm name="Election">Voting</indexterm>
</book>

T:\ftemp>type philip.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each-group select="/*/indexterm"
group-by="substring(@name,1,1)">
    <xsl:sort select="@name"/>
    <xsl:text>
</xsl:text>
    <xsl:value-of select="current-grouping-key()"/>
    <xsl:text>
</xsl:text>
    <xsl:for-each-group select="current-group()" group-by="@name">
      <xsl:value-of select="current-grouping-key()"/>
      <xsl:text>
</xsl:text>
      <xsl:for-each select="current-group()">
        <xsl:sort select="."/>
        <xsl:text/> - <xsl:value-of select="."/><xsl:text>
</xsl:text>
      </xsl:for-each>
    </xsl:for-each-group>
  </xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt2 philip.xml philip.xsl con

E
E190
 - Aircraft Tail
 - Landing Gear
Election
 - Voting

G
GMM
 - Aircraft Logbook Entry
 - MX-4 Deffered Items

S
Smith Airways
 - MEL Policy and Revision number

T:\ftemp>

--
UBL/XSLT/XSL-FO training: Allerxd/Verx Denmark 2006-11-13,17,20/24
UBL International 2006  2006-11-13/17 http://www.ublconference.com
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--
Regards,
Mukul Gandhi


Current Thread
Keywords