|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Request hints for creating TOC in HTML table
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 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!
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








