Subject: Re: [xsl] TOC Problem (XSL2 solution) From: JBryant@xxxxxxxxx Date: Wed, 2 Mar 2005 16:42:10 -0600 |
Hi, Frank, I generate my tables of contents by using a separate mode for it. (I also use another mode for creating the bookmarks.) Since you want to list multiple page numbers on one line, you need to group the speech elements by speaker. That's easy with XSL2 (use for-each-group) and not so easy with XSL1 (use a recursive template) Thus, for your document, my stylesheet would look like this: <xsl:template match="/"> <xsl:apply-templates mode="contents"/> <xsl:apply-templates/> </xsl:template> <xsl:template match="protocoll"> <xsl:apply-templates/> </xsl:template> <xsl:template match="protocoll" mode="contents"> <xsl:for-each-group select="speech" group-by="speaker/@name"> <fo:block> <xsl:value-of select="speaker/@name"/> <fo:leader leader-pattern="dots" leader-length.maximum="100%"/> <xsl:variable name="nameToCompare" select="speaker/@name"/> <xsl:for-each select="/protocoll/speech/speaker[@name=$nameToCompare]"> <!-- need some logic to deal with commas --> <fo:page-number-citation ref-id="{generate-id(.)}"/> </xsl:for-each> </fo:block> </xsl:for-each-group> </xsl:template> <xsl:template match="speech"> <!-- Build the body of the document --> </xsl:template> I tested this with Saxon 8 on the following XML file: <protocoll> <speech> <speaker name="Joe" id="Joe1">This is a long content of a speech.</speaker> </speech> <speech> <speaker name="Bob" id="Bob1">This is a long content of a speech.</speaker> </speech> <speech> <speaker name="Joe" id="Joe2">This is a long content of a speech.</speaker> </speech> <speech> <speaker name="Bob" id="Bob2">This is a long content of a speech.</speaker> </speech> <speech> <speaker name="Joe" id="Joe3">This is a long content of a speech.</speaker> </speech> </protocoll> It produced this: <?xml version="1.0" encoding="UTF-8"?> <fo:block>Joe<fo:leader leader-pattern="dots" leader-length.maximum="100%"/> <fo:page-number-citation ref-id="d1e5"/> <fo:page-number-citation ref-id="d1e17"/> <fo:page-number-citation ref-id="d1e29"/> </fo:block> <fo:block>Bob<fo:leader leader-pattern="dots" leader-length.maximum="100%"/> <fo:page-number-citation ref-id="d1e11"/> <fo:page-number-citation ref-id="d1e23"/> </fo:block> If you need the XSL1 solution, I refer you to Jeni Tennison's site, which Wendell's message mentioned. HTH Jay Bryant Bryant Communication Services (presently consulting at Synergistic Solution Technologies) Frank Lorenz <f.lo@xxxxxx> 03/02/2005 02:38 PM Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx To xsl-list@xxxxxxxxxxxxxxxxxxxxxx cc Subject [xsl] TOC Problem Hi, i need a hint creating a table of content from underlying XML data. The XML is transformed via XSLT to FO. The generated pdf then shows the TOC - actually it does not :-( The TOC should display the speaker on the left and all the starting pagenumbers of the speech's beginning on the right. The problem is that one speaker could speak at several times, which means that there are several speechs per speaker distributet on several pages. It does not seem that XSLT respectively FO can handle this problem... Regards Frank ------------------------------------ Table Of Content Joe..........1,5,6 Bob............3,7 ------------------------------------ Underlying XML data: <protocoll> <speech> <speaker name="Joe" id="Joe1"> This is a long content of a speech... </speech> <speech> <speaker name="Bob" id="Bob1"> This is a long content of a speech... </speech> <speech> <speaker name="Joe" id="Joe2"> This is a long content of a speech... </speech> ... </protocoll>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] TOC Problem, Wendell Piez | Thread | RE: [xsl] TOC Problem, Pawson, David |
Re: [xsl] Chunking xml into single-, Kessler, Marcy | Date | Re: [xsl] most efficient way to che, Sebastien Boisvert |
Month |