[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Keeping an eye on processed nodes

Subject: RE: Keeping an eye on processed nodes
From: "Ross Ken" <Ken.Ross@xxxxxxxxxxxxxx>
Date: Thu, 16 Jan 2003 08:12:02 +1000
fo block newline
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::*[@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[@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[@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.Ross@xxxxxxxxxxxxxx


-----Original Message-----
From: Gustaf Liljegren [mailto:gustaf.liljegren@xxxxxx]
Sent: Thursday, 16 January 2003 3:41 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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[@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[@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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.