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

Re: [xsl] Bookmarks in xsl

Subject: Re: [xsl] Bookmarks in xsl
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 05 Sep 2012 11:33:51 -0400

At 2012-09-05 09:44 -0500, a kusa wrote:
Thanks for your response Ken.

> The first bookmark of the entire set or the first bookmark of the chapter? - I meant the first bookmark of the chapter.

And when I said 'under' I meant nested bookmarks.

The problem I am having is that since the element 'task' can repeat
for a chapter, I am unable to generate the bookmark internal
destination ids to be unique. Since FOP does not support XSLT 1.0 (
and I restricted to this product),  I am not able to use the xslt 2.0
for-each-group to be able to group the tasks. I have to use keys to
group them. Is there any other better way of doing this?

"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:


BTW, I describe XSL-FO bookmarks in chapter 9 section 1 of my XSL-FO book here:


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"?>

<task chap="8" key="a123" seq="1" pg = "1">
<!-- some more content here-->

<task chap="8" key="y837458" seq="2" pg = "2">
<!-- some more content here-->
<task chap="9" key="3jkhkj" seq="1" pg = "1">
<!-- some more content here-->
<task chap="9" key="t8798" seq="2" pg = "2">
<!-- some more content here-->
~/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 internal-destination="d0e8">
   <bookmark internal-destination="d0e13">
      <bookmark internal-destination="d0e18">
</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"

<xsl:output indent="yes"/>

<xsl:key name="tasks" match="task" use="@chap"/>

<xsl:template match="tasks">
    <xsl:for-each select="task[generate-id(.)=
      <bookmark internal-destination="{generate-id(.)}">
          <xsl:value-of select="@chap"/>
        <xsl:for-each select="key('tasks',@chap)[position()>1]">
          <bookmark internal-destination="{generate-id(.)}">
              <xsl:value-of select="concat(@chap,'-',@seq)"/>

</xsl:stylesheet>~/t/ftemp $
~/t/ftemp $

-- Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012 Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread