Loading ...
Sorry, an error occurred while loading the content.

Index creation trouble!

Expand Messages
  • Anders Svensson
    I m creating an index with XSLT and have done this successfully several times for the document in question. The XSL creates an index that is sorted
    Message 1 of 1 , Mar 8, 2002
    • 0 Attachment
      I'm creating an index with XSLT and have done this successfully several times for the document in question. The XSL creates an index that is sorted alphabetically and groups sub-entries under single main entries (i.e. if there are several identical main entries with different sub-entries the main entry will not be duplicated, but the sub-entries will be listed under one instance of the main entry). However, the last functionality stopped working in the pdf version of the documents all of a sudden. Suddenly the sub-entries were NOT grouped, but rather had a separate instance each of the main entry. The odd thing is that although I have changed some things in the XSL slightly, I tried the old version of the XSL as well, but it still didn't work (!) How is this possible? How can FOP work and create a perfect index one time and fail completely the next when nothing else has changed?

      I have been a little puzzled by some inconsistencies due to different parser behaviours, and I wonder if this could be caused by that as well...? Because I initially used MSXML to transform docs, but found that there were problems with UTF-16 vs UTF-8. Apparently our documents are written with UTF-8, but MSXML interprets them as UTF-16 and screws up Swedish characters needed in the documents. So I switched to Xalan, which handled these characters better.

      Now, when the index problem arose I tried a transformation on an older document compiled with MSXML and the index creation (with grouping) worked like a charm in there! That doesn't solve my problem one bit though, because of the Swedish character thing in MSXML... This is driving me crazy to say the least! Does anyone know what is happening and what to do? Please help.

      Here's a snippet of the XSLT for the index:

      At top of stylesheet:
      <xsl:key name="letters" match="//Index-entry"
      use="translate (substring(@Main,1,1),
      'abcdefghijklmnopqrstuvwxyz1234567890@',
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ###########')" />

      The index creation bit itself:

      <fo:flow flow-name="xsl-region-body">

      <!--***********************************************************'-->
      <fo:block start-indent="15pt" break-before="page">

      <xsl:for-each select="//Index-entry[count(. | key('letters',
      translate (substring(@Main,1,1),
      'abcdefghijklmnopqrstuvwxyz1234567890@',
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ###########'))[1]) = 1]">

      <xsl:sort select="@Main" />
      <xsl:variable name="initial"
      select="translate (substring(@Main,1,1),
      'abcdefghijklmnopqrstuvwxyz1234567890@',
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ###########')" />

      <!--RUBRIKBOKSTAVEN SKRIVS UT HÄR-->

      <xsl:choose>
      <xsl:when test ="$initial = '#'">
      <fo:block font-size="14pt"
      line-height="18pt"
      space-before.optimum="20pt"
      space-after.optimum="10pt"
      font-weight="bold"

      >Numbers & symbols</fo:block>
      </xsl:when>
      <xsl:otherwise>
      <fo:block font-size="14pt"
      line-height="18pt"
      space-before.optimum="20pt"
      space-after.optimum="10pt"
      font-weight="bold"

      ><xsl:value-of select="$initial" /></fo:block>

      </xsl:otherwise>
      </xsl:choose>
      <fo:block></fo:block> <!--TOM RAD-->


      <xsl:for-each select="key('letters', $initial)">
      <xsl:sort select="@Main" />
      <xsl:if test="not(ancestor::Overview)">
      <xsl:apply-templates select="self::Index-entry[not(./@Sub)] | self::Index-entry[./@Sub]"></xsl:apply-templates>
      </xsl:if>
      </xsl:for-each>

      </xsl:for-each>


      </fo:block>
      </fo:flow>
      </fo:page-sequence>
      </fo:root>
      </xsl:template>


      <xsl:template match="Index-entry[not(@Sub)]">
      <fo:block line-height="18pt" text-align-last="start"> <fo:inline font-size="15pt"><xsl:value-of select="@Main"/> <xsl:if test="not(./@Sub)">
      <xsl:text>, </xsl:text>
      <fo:page-number-citation ref-id="{generate-id(ancestor::Textblock)}"/>
      </xsl:if>
      </fo:inline>
      </fo:block>
      </xsl:template>


      <xsl:template match="Index-entry[@Sub]">
      <xsl:if test="self::Index-entry/@Main[not(.=preceding::Index-entry/@Main)]">
      <fo:block line-height="18pt" text-align-last="start"> <fo:inline font-size="12pt"><xsl:value-of select="@Main[not(.=preceding::Index-entry/@Main)]"/>
      <xsl:text>, </xsl:text>
      <fo:page-number-citation ref-id="{generate-id(ancestor::Textblock)}"/>
      </fo:inline>
      </fo:block>
      </xsl:if>

      <fo:block font-style="italic" start-indent="30pt" line-height="15pt" text-align-last="start">
      <fo:inline font-size="12pt"><xsl:value-of select="@Sub"/>
      <xsl:text>, </xsl:text>
      <fo:page-number-citation ref-id="{generate-id(Textblock)}"/>
      </fo:inline>
      </fo:block>
      </xsl:template>

      Best regards,

      Anders Svensson
    Your message has been successfully submitted and would be delivered to recipients shortly.