[xsl] Converting a Table of Contents to an index

Subject: [xsl] Converting a Table of Contents to an index
From: Jim Freeman <jim@xxxxxxxxxxxxxxxx>
Date: Wed, 10 Apr 2002 21:15:35 -0700
I am trying to invert a tree - specifically to create an index for a document by pulling the leaves to the top and grouping them. A classic problem that I am just having a mental block on . . . ARGHHHH!!!

I won't begin to include all the XSL attempts - but will include the source and target . . . .

Here is the source XML:

<?xml version="1.0" encoding="UTF-8"?>
<book>
        <chapter title="Chapter 1">
                <para>
                        <text>This is a trip overview</text>
                        <index>travel</index>
                        <index>overview</index>
                </para>
                <para>
                        <text>This is about planning</text>
                        <index>travel</index>
                        <index>planning</index>
                </para>
                <para>
                        <text>This is about packing</text>
                        <index>travel</index>
                        <index>packing</index>
                </para>
        </chapter>
        <chapter title="Chapter 2">
                <para>
                        <text>This is about travel in europe</text>
                        <index>europe</index>
                        <index>travel</index>
                </para>
        </chapter>
</book>

And here is the output XML:

<?xml version="1.0" encoding="UTF-8"?>
<index>
        <entry>
                <text>travel</text>
                <referenceChapter name="Chapter 1">
                        <referencePara>1</referencePara>
                        <referencePara>2</referencePara>
                        <referencePara>3</referencePara>
                </referenceChapter>
                <referenceChapter name="Chapter 2">
                        <referencePara>1</referencePara>
                </referenceChapter>
        </entry>
        <entry>
                <text>overview</text>
                <referenceChapter name="Chapter 1">
                        <referencePara>1</referencePara>
                </referenceChapter>
        </entry>
        <entry>
                <text>planning</text>
                <referenceChapter name="Chapter 1">
                        <referencePara>1</referencePara>
                </referenceChapter>
        </entry>
        <entry>
                <text>packing</text>
                <referenceChapter name="Chapter 1">
                        <referencePara>3</referencePara>
                </referenceChapter>
                <entry>
                        <text>europe</text>
                        <referenceChapter name="Chapter 2">
                                <referencePara>1</referencePara>
                        </referenceChapter>
                </entry>
        </entry>
</index>


















James C. Freeman mailto:jim@xxxxxxxxxxxxxxxx Voice: 415 971 6541 Fax: 413 622 8955


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



Current Thread