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