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:


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 $


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