[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Bookmarks in xsl
At 2012-09-05 09:44 -0500, a kusa wrote:
Thanks for your response Ken. "Better"? No. In my class and in my book I point out there are three ways to do grouping in XSLT 1.0: by axes (best for adjacent grouping), by keys (best for full-document grouping) and by variables (best for sub-document grouping and multiple-document grouping). I describe these approaches starting on page 411 of my XSLT book that can be downloaded in its entirety in a "try and buy" format in either A4 or US-letter page sizes here: http://www.CraneSoftwrights.com/training/#ptux BTW, I describe XSL-FO bookmarks in chapter 9 section 1 of my XSL-FO book here: http://www.CraneSoftwrights.com/training/#pfux If you only have one set of tasks and you need to group them by chapter, then key-based grouping is the best for XSLT 1.0. I hope the example below helps. . . . . . . . . . Ken ~/t/ftemp $ cat kusa.xml <?xml version="1.0" encoding="UTF-8"?> <tasks> <task chap="8" key="a123" seq="1" pg = "1"> <!-- some more content here--> </task> <task chap="8" key="y837458" seq="2" pg = "2"> <!-- some more content here--> </task> <task chap="9" key="3jkhkj" seq="1" pg = "1"> <!-- some more content here--> </task> <task chap="9" key="t8798" seq="2" pg = "2"> <!-- some more content here--> </task> </tasks> ~/t/ftemp $ xslt kusa.xml kusa.xsl <?xml version="1.0" encoding="utf-8"?> <bookmark-tree xmlns="http://www.w3.org/1999/XSL/Format"> <bookmark internal-destination="d0e3"> <bookmark-title>8</bookmark-title> <bookmark internal-destination="d0e8"> <bookmark-title>8-2</bookmark-title> </bookmark> </bookmark> <bookmark internal-destination="d0e13"> <bookmark-title>9</bookmark-title> <bookmark internal-destination="d0e18"> <bookmark-title>9-2</bookmark-title> </bookmark> </bookmark> </bookmark-tree>~/t/ftemp $ ~/t/ftemp $ cat kusa.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XSL/Format" version="1.0"> <xsl:output indent="yes"/> <xsl:key name="tasks" match="task" use="@chap"/> <xsl:template match="tasks"> <bookmark-tree> <xsl:for-each select="task[generate-id(.)= generate-id(key('tasks',@chap)[1])]"> <bookmark internal-destination="{generate-id(.)}"> <bookmark-title> <xsl:value-of select="@chap"/> </bookmark-title> <xsl:for-each select="key('tasks',@chap)[position()>1]"> <bookmark internal-destination="{generate-id(.)}"> <bookmark-title> <xsl:value-of select="concat(@chap,'-',@seq)"/> </bookmark-title> </bookmark> </xsl:for-each> </bookmark> </xsl:for-each> </bookmark-tree> </xsl:template> </xsl:stylesheet>~/t/ftemp $ ~/t/ftemp $
|
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
|