xsl-list
[Top] [All Lists]

RE: Keeping an eye on processed nodes

2003-01-15 15:12:02
Try

  <xsl:template match="entry">
    <xsl:variable name="context" select="@context"/>
    <xsl:choose>
      <!-- If the entry has a certain context... -->
      <xsl:when test="@context">
<!-- New line - only print the header if you haven't already -->
        <xsl:if test="not(preceding-sibling::*[(_at_)context=$context])" >

        <!-- ...print the context, then... -->
        <fo:block xsl:use-attribute-sets="entries">
          <xsl:value-of select="@context"/>
        </fo:block>

<!-- New line -->
        </xsl:if>

        <!-- ...print each entry within this context -->

<!-- Delete this line        <xsl:for-each select="//entry[(_at_)context = 
$context]"> -->
          <fo:block xsl:use-attribute-sets="entries">
            <xsl:attribute name="margin-left">1em</xsl:attribute>
            <xsl:call-template name="print-entry"/>
          </fo:block>
<!-- Delete this line        </xsl:for-each> -->
      </xsl:when>
      <!-- If the entry has no context -->
      <xsl:otherwise>
        <fo:block xsl:use-attribute-sets="entries">
          <xsl:call-template name="print-entry"/>
        </fo:block>
        <!-- Look for other entries with this context -->
        <xsl:for-each select="//entry[(_at_)context = text()]">
          <fo:block xsl:use-attribute-sets="entries">
            <xsl:attribute name="margin-left">1em</xsl:attribute>
            <xsl:call-template name="print-entry"/>
          </fo:block>
        </xsl:for-each>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


HTH,

Ken Ross
Ph: +61 7 32359370
Mob: +61 (0)419 772299
Email: Ken(_dot_)Ross(_at_)iie(_dot_)qld(_dot_)gov(_dot_)au


-----Original Message-----
From: Gustaf Liljegren [mailto:gustaf(_dot_)liljegren(_at_)xml(_dot_)se]
Sent: Thursday, 16 January 2003 3:41 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Keeping an eye on processed nodes


I'm doing something really wrong here. I'm trying to process an index for a
book, and find myself in a situation where I need to keep an eye on which
nodes I have already processed. Since this is not possible in XSLT, I need
your help to find an alterntive solution. Part of the XML:

<?xml version="1.0" encoding="iso-8859-1"?>
<index>
  ...
  <entry page="34">A4 page size</entry>
  <entry page="37">absolute direction</entry>
  <entry page="172" context="absolute-position property">correcting
    content position with</entry>
  <entry page="91" context="absolute-position property">offsetting
    content with</entry>
  <entry page="139">alignment points</entry>
  ...
</index>

This should be rendered as:

A4 page size, 34
absolute direction, 37
absolute-position property
  correcting content position with, 172
  offsetting content with, 91
alignment points, 139

The entry template in the XSL file:

  <!-- TM: Index entries -->
  <xsl:template match="entry">
    <xsl:variable name="context" select="@context"/>
    <xsl:choose>
      <!-- If the entry has a certain context... -->
      <xsl:when test="@context">
        <!-- ...print the context, then... -->
        <fo:block xsl:use-attribute-sets="entries">
          <xsl:value-of select="@context"/>
        </fo:block>
        <!-- ...print each entry within this context -->
        <xsl:for-each select="//entry[(_at_)context = $context]">
          <fo:block xsl:use-attribute-sets="entries">
            <xsl:attribute name="margin-left">1em</xsl:attribute>
            <xsl:call-template name="print-entry"/>
          </fo:block>
        </xsl:for-each>
      </xsl:when>
      <!-- If the entry has no context -->
      <xsl:otherwise>
        <fo:block xsl:use-attribute-sets="entries">
          <xsl:call-template name="print-entry"/>
        </fo:block>
        <!-- Look for other entries with this context -->
        <xsl:for-each select="//entry[(_at_)context = text()]">
          <fo:block xsl:use-attribute-sets="entries">
            <xsl:attribute name="margin-left">1em</xsl:attribute>
            <xsl:call-template name="print-entry"/>
          </fo:block>
        </xsl:for-each>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

The problem occurs when several words are grouped. For each entry within
the same @context, a new group is made, like this:

absolute-position property
  correcting content position with, 172
  offsetting content with, 91
absolute-position property
  correcting content position with, 172
  offsetting content with, 91

Another related problem occurs on entries without @context, but other
entries with matching @context attributes, like this:

<entry page="129-132">background-color property</entry>
<entry page="94" context="background-color property">images and</entry>

This should be rendered as:

background-color property, 129-132
  images and, 94

For each new entry, I check if there are any entries with a matching
@context and list them below. But the result is:

background-color property, 129-132
background-color property
  images and, 94

Gustaf



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

IMPORTANT: This email (including any attachments) may contain confidential,
private or legally privileged information and may be protected by copyright. 
You may
only use it if you are the person(s) it was intended to be sent to and if you 
use it in an
authorised way. No one is allowed to use, review, alter, transmit, disclose, 
distribute,
print or copy this e-mail without appropriate authority.
 
If this e-mail was not intended for you and was sent to you by mistake, please
telephone or e-mail me immediately, destroy any hard copies of this e-mail and 
delete
it and any copies of it from your computer system. Any legal privilege and 
confidentiality attached to this e-mail is not waived or destroyed by that 
mistake.
 
It is your responsibility to ensure that this e-mail does not contain and is 
not affected
by computer viruses, defects or interference by third parties or replication 
problems
(including incompatibility with your computer system).




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>