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

Re: [xsl] Request hints for creating TOC in HTML table


Subject: Re: [xsl] Request hints for creating TOC in HTML table
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Jan 2004 17:35:22 -0500

At 2004-01-19 22:56 +0100, Thomas V. Nielsen wrote:
I'll think something like this must have been done a thousand times before,

I've done this for my own stuff.


I have a xml document e.g.
...
What I would like is to transform this document into a HTML table like with
four columns

-----------------------------
| #    | E    | J    | Q    |
|365 BC|      |      | R    |
| A    | F    | K    | S    |
|alpha |      | L    | T    |
| B    | G    | M    | U    |
|bedroc| H    | N    | V    |
| C    | I    | O    | X    |
| D    |      | P    | Z    |
-----------------------------

Right know I can't either figure out how to sort the items in groups,

That part is below. Note that the entities are not required but I find it easier when doing some grouping tasks. Each of these are only used once, but should they be needed elsewhere then the entities are handy and ready to use.


or find out how many groups to put into each column to make it look nice.

*That* part will take two passes ... I think it would be a lot easier than trying a recursive call.


I used text, you can change it to put out XML for the second pass.

I hope this helps.

............................... Ken

T:\ftemp>type thomas.xml
<content>
        <item>bedrock</item>
        <item>alphaville</item>
        <item>Zebra</item>
        <item>365 BC</item>
        <item>alpha2</item>
        <item>alphaz</item>
        ...
</content>

T:\ftemp>type thomas.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY lower 'abcdefghijklmnopqrstuvwxyz0123456789'>
<!ENTITY upper 'ABCDEFGHIJKLMNOPQRSTUVWXYZ##########'>
<!ENTITY first 'translate(substring(.,1,1),"&lower;","&upper;")'>
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:i="internal"
                version="1.0">

<xsl:key name="firsts" match="item" use="&first;"/>

<xsl:output method="text"/>

<i:index>
  <l>#</l>  <l>A</l>  <l>B</l>  <l>C</l>  <l>D</l>  <l>E</l>
  <l>F</l>  <l>G</l>  <l>H</l>  <l>I</l>  <l>J</l>  <l>K</l>  <l>L</l>
  <l>M</l>  <l>N</l>  <l>O</l>  <l>P</l>  <l>Q</l>  <l>R</l>  <l>S</l>
  <l>T</l>  <l>U</l>  <l>V</l>  <l>W</l>  <l>X</l>  <l>Y</l>  <l>Z</l>
</i:index>

<xsl:template match="/">
  <xsl:variable name="input" select="/"/>
  <xsl:for-each select="document('')/*/i:index/l">
    <xsl:value-of select="."/><xsl:text>
</xsl:text>
    <xsl:variable name="index" select="."/>
    <xsl:for-each select="$input">
      <xsl:for-each select="key('firsts',$index)">
        <xsl:sort/>
        <xsl:value-of select="."/><xsl:text>
</xsl:text>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon thomas.xml thomas.xsl
#
365 BC
A
alpha2
alphaville
alphaz
B
bedrock
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Zebra

T:\ftemp>rem Done!


-- North America (Washington, DC): 3-day XSLT/2-day XSL-FO 2004-03-15 - (San Francisco, CA): 3-day XSLT/2-day XSL-FO 2004-03-22 Asia (Hong Kong, China): 3-day XSLT/2-day XSL-FO 2004-05-17 Europe (Bremen, Germany): 3-day XSLT/2-day XSL-FO 2004-05-24 Instructor-led on-site corporate, government & user group training for XSLT and XSL-FO world-wide: please contact us for the details

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 Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


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




Current Thread
Keywords